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

module.exports = (sequelize) => {
    const ProgressionTable = sequelize.define('progressiontable', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        scope_development: { type: DataTypes.STRING, allowNull: true },
        achievement_detail: { type: DataTypes.TEXT, allowNull: true },
        achievement_level: { type: DataTypes.STRING, allowNull: true },

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

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


    return ProgressionTable;
};
