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

module.exports = (sequelize) => {
    const MedicalRecord = sequelize.define('medicalrecord', {
        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
        admission_day: { type: DataTypes.STRING(10), allowNull: false },
        admission_date: { type: DataTypes.DATEONLY, allowNull: false },
        admission_time: { type: DataTypes.TIME, allowNull: false },
        discharge_day: { type: DataTypes.STRING(10), allowNull: true },
        discharge_date: { type: DataTypes.DATEONLY, allowNull: true },
        discharge_time: { type: DataTypes.TIME, allowNull: true },
        current_diagnosis: { type: DataTypes.TEXT, allowNull: true },
        current_comorbidity: { type: DataTypes.TEXT, allowNull: true },
        current_symptom: { type: DataTypes.TEXT, allowNull: true },

        // fk
        patient_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            references: {
                model: 'patients',
                key: 'id'
            }
        },
        hospital_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            references: {
                model: 'hospitals',
                key: 'id'
            }    
        },
        doctor_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            references: {
                model: 'doctors',
                key: 'id'
            }
        },

    }, {
        tableName: 'medicalrecords',
        freezeTableName: true
    });

    /**
     * Associates the MedicalRecord model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    MedicalRecord.associate = (models) => {

    };

    return MedicalRecord;
};
