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

module.exports = (sequelize) => {
    const BodyTemperature = sequelize.define('bodytemperature', {
        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(50), allowNull: false },
        display_name: { type: DataTypes.STRING(50), allowNull: false },
        description: { type: DataTypes.STRING(255), allowNull: true },
        temperature_min: { type: DataTypes.FLOAT, allowNull: true },
        temperature_max: { type: DataTypes.FLOAT, allowNull: true },
        
        // fk
        company_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            references: {
                model: 'companies',
                key: 'id'
            }
        },
    }, {
        tableName: 'bodytemperatures',
        freezeTableName: true
    });

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

    return BodyTemperature;
};
