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

module.exports = (sequelize) => {
    const PatientMedication = sequelize.define('patientmedication', {
        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 },

        // main
        dosage: { type: DataTypes.TEXT, allowNull: true },
        frequency: { type: DataTypes.TEXT, allowNull: true },
        duration: { type: DataTypes.TEXT, allowNull: true },
        administration_method: { type: DataTypes.STRING(100), allowNull: true },
        notes: { type: DataTypes.TEXT, allowNull: true },
        description: { type: DataTypes.TEXT, allowNull: true },

        // fk
        patient_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            references: {
                model: 'patients',
                key: 'id'
            }
        },
        drug_id: {
            type: DataTypes.INTEGER,
            allowNull: true,
            references: {
                model: 'drugs',
                key: 'id'
            }
        },
    }, {
        tableName: 'patientmedications',
        freezeTableName: true
    });

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

    };

    return PatientMedication;
};
