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

module.exports = (sequelize) => {
    const Visite = sequelize.define('visite', {
        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
        day: { type: DataTypes.STRING(10), allowNull: false },
        date: { type: DataTypes.DATEONLY, allowNull: false },
        time: { type: DataTypes.TIME, allowNull: false },
        description: { 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: 'visites',
        freezeTableName: true
    });

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

    };

    return Visite;
};
