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

module.exports = (sequelize) => {
    const Hospital = sequelize.define('hospital', {
        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(100), allowNull: false },
        display_name: { type: DataTypes.STRING(100), allowNull: false },
        address: { type: DataTypes.TEXT, allowNull: true },
        phone: { type: DataTypes.STRING(50), allowNull: true },
        mobile_no: { type: DataTypes.STRING(50), allowNull: true },
        email: { type: DataTypes.STRING(50), allowNull: true },
        website: { type: DataTypes.STRING(50), allowNull: true },
        logo: { type: DataTypes.STRING, allowNull: true },
        image: { type: DataTypes.STRING, allowNull: true },
        
        // fk
    }, {
        tableName: 'hospitals',
        freezeTableName: true
    });

    /**
     * Associates the Hospital model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    Hospital.associate = (models) => {
        Hospital.hasMany(models.Patient, { foreignKey: 'hospital_id', as: 'patients' });
    };

    return Hospital;
};
