'use strict';

module.exports = (sequelize, DataTypes) => {
    const Users = sequelize.define('Users', {
        id: {
            allowNull: false,
            autoIncrement: true,
            primaryKey: true,
            type: DataTypes.INTEGER
        },
        name: {
            allowNull: false,
            type: DataTypes.STRING
        },
        surname: {
            allowNull: false,
            type: DataTypes.STRING
        },
        email: {
            allowNull: false,
            unique: true,
            type: DataTypes.STRING
        },
        birthDay: {
            allowNull: false,
            type: DataTypes.STRING
        },
        phone: {
            allowNull: false,
            type: DataTypes.STRING
        },
        city: {
            allowNull: false,
            type: DataTypes.STRING
        },
        street: {
          allowNull: false,
          type: DataTypes.STRING
        },
        home: {
            allowNull: false,
            type: DataTypes.STRING
        },
        apartment: {
            allowNull: true,
            type: DataTypes.STRING
        },
        postIndex: {
            allowNull: false,
            type: DataTypes.INTEGER
        },
        role: {
            allowNull: false,
            type: DataTypes.STRING
        },
        password: {
            allowNull: false,
            type: DataTypes.STRING
        },
        token: {
            allowNull: true,
            type: DataTypes.STRING
        }
    });

    Users.associate = function (models) {
        Users.hasMany(models.GoodsFavourites, {foreignKey: 'userId', targetKey: 'id'});
    };

    return Users;
};
