const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
    const UserAdditionalInfo = sequelize.define('useradditionalInfo', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        gender: { type: DataTypes.STRING(20), allowNull: true },
        age: { type: DataTypes.INTEGER, allowNull: true },
        occupation: { type: DataTypes.STRING(200), allowNull: true },
        last_education: { type: DataTypes.STRING(200), allowNull: true },
        salary: { type: DataTypes.STRING(200), allowNull: true },

        // fk
        user_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
                model: 'Users',
                key: 'id'
            }
        },
    }, {
        tableName: 'useradditionalinfos',
    }, {
        freezeTableName: true
    });

    /**
     * Associates the UserAdditionalInfo model with other models.
     * @param {object} models - The models to associate with.
     * @description
     *   - A UserAdditionalInfo belongs to one User.
     */
    UserAdditionalInfo.associate = (models) => {
        /**
         * Associates the UserAdditionalInfo model with the User model.
         * @param {object} models - The models to associate with.
         * @description
         *   - A UserAdditionalInfo belongs to one User.
         */
        UserAdditionalInfo.belongsTo(models.User, { foreignKey: 'user_id', as: 'user' });
    };

    return UserAdditionalInfo;
};
