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

module.exports = (sequelize) => {
    const BloodPressure = sequelize.define('bloodpressure', {
        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
        name: { type: DataTypes.STRING(150), allowNull: false },
        display_name: { type: DataTypes.STRING(150), allowNull: false },
        description: { type: DataTypes.TEXT, allowNull: true },
        systolic_min: { type: DataTypes.INTEGER, allowNull: true },
        systolic_max: { type: DataTypes.INTEGER, allowNull: true },
        diastolic_min: { type: DataTypes.INTEGER, allowNull: true },
        diastolic_max: { type: DataTypes.INTEGER, allowNull: true },
        age_min: { type: DataTypes.INTEGER, allowNull: true },
        age_max: { type: DataTypes.INTEGER, allowNull: true },

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

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

    return BloodPressure;
};
