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

module.exports = (sequelize) => {
    const GimmickReqSubType = sequelize.define('gimmickreqsubtype', {
        id: {
            type: DataTypes.INTEGER,
            autoIncrement: true,
            primaryKey: true
        },
        creation: { type: DataTypes.DATE, allowNull: false },
        modified: { type: DataTypes.DATE, allowNull: false },
        modified_by: { type: DataTypes.INTEGER, allowNull: false },
        owner: { type: DataTypes.INTEGER, allowNull: false },
        enabled: { type: DataTypes.BOOLEAN, allowNull: false },

        // main
        display_name: {type: DataTypes.STRING, allowNull: false, unique: true},
        tax_type: {type: DataTypes.STRING, allowNull: true},
        tax_percent: {type: DataTypes.INTEGER, allowNull: false},
        estimate_day_realization: {type: DataTypes.INTEGER, allowNull: true},

        // fk
         gimmickreqtype_id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            references: {
            model: "gimmickreqtypes",
            key: "id",
            },
        },
      
    }, {
        tableName: 'gimmickreqsubtypes',
        freezeTableName: true
    });

    /**
     * Associates the Drug model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    GimmickReqSubType.associate = (models) => {
        GimmickReqSubType.belongsTo(models.GimmickReqType, { foreignKey: "gimmickreqtype_id", as: "reqtype", onDelete: 'CASCADE' });
        GimmickReqSubType.hasMany(models.GimmickRequest, { foreignKey: "gimmickrequestsubtype_id", as: "gimmickrequest" });
    };

    return GimmickReqSubType;
};
