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

module.exports = (sequelize) => {
    const Aspect = sequelize.define('aspect', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        aspect_name: { type: DataTypes.STRING, allowNull: false },
        description: { type: DataTypes.TEXT, allowNull: false },

        // fk
        development_id: { 
            type: DataTypes.INTEGER, 
            references: { 
                model: 'developments', 
                key: 'id' 
            }, 
            onDelete: 'CASCADE' 
        },
    }, {
        indexes: [{ fields: ['development_id'] }],
    }, {
        tableName: 'aspects',
    }, {
        freezeTableName: true
    });

    /**
     * Associates the Aspect model with other models.
     * @param {object} models - The models to associate with.
     */
    Aspect.associate = (models) => {
        /**
         * Associate the Aspect model with the Development model.
         * @param {object} models - The models to associate with.
         */
        Aspect.belongsTo(models.Development, { foreignKey: 'development_id', as: 'development' });
    };

    return Aspect;
};
