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

module.exports = (sequelize) => {
    const PulseAgeRate = sequelize.define('pulseagerate', {
        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
        age: { type: DataTypes.INTEGER, allowNull: false },
        age_min: { type: DataTypes.INTEGER, allowNull: true },
        age_max: { type: DataTypes.INTEGER, allowNull: true },
        bpm_min: { type: DataTypes.INTEGER, allowNull: true },
        bpm_max: { type: DataTypes.INTEGER, allowNull: true },
        bpm_maximum: { type: DataTypes.INTEGER, allowNull: true },

        // fk
        company_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
        },
    }, {
        tableName: 'pulseagerates',
        freezeTableName: true
    });

    /**
     * Associates the PulseAgeRate model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    PulseAgeRate.associate = (models) => {
        PulseAgeRate.belongsTo(models.Company, { foreignKey: "company_id", as: "company" });
    };

    return PulseAgeRate;
};
