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

module.exports = (sequelize) => {
    const MedicalExaminationItem = sequelize.define('medicalexaminationitem', {
        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
        name: { type: DataTypes.STRING(150), allowNull: false },
        display_name: { type: DataTypes.STRING(150), allowNull: false },
        description: { type: DataTypes.TEXT, allowNull: true },

        // fk
        medicalexamination_id: {
            type: DataTypes.INTEGER,
            allowNull: false
        }
    }, {
        tableName: 'medicalexaminationitems',
        freezeTableName: true
    });

    /**
     * Associates the MedicalExamination model with other models.
     * @param {object} models - The models to associate with.
     * @description
     */
    MedicalExaminationItem.associate = (models) => {
        MedicalExaminationItem.belongsTo(models.MedicalExamination, { foreignKey: 'medicalexamination_id', as: 'medicalexamination' });
    };

    return MedicalExaminationItem;
};
