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

module.exports = (sequelize) => {
    const Mom = sequelize.define(
        "mom",
        {
            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: true },
            owner: { type: DataTypes.INTEGER, allowNull: true },
            enabled: { type: DataTypes.BOOLEAN, allowNull: false },

            meeting_name: { type: DataTypes.STRING(100), allowNull: false },
            meeting_date: { type: DataTypes.DATEONLY, allowNull: false },
            time_start: { type: DataTypes.TIME, allowNull: false },
            time_end: { type: DataTypes.TIME, allowNull: false },
            location: { type: DataTypes.STRING(100), allowNull: false },
            conclusion: { type: DataTypes.TEXT, allowNull: true },
            followup: { type: DataTypes.TEXT, allowNull: true },

            results: { type: DataTypes.TEXT, allowNull: true },
            comments: { type: DataTypes.JSON, allowNull: true },
            files: {type: DataTypes.TEXT, allowNull: true},
        },
        {
            tableName: "moms",
            freezeTableName: true,
        }
    );

    Mom.associate = (models) => {
        Mom.hasMany(models.MomParticipant, { as: "momparticipants", foreignKey: "mom_id" });
        Mom.hasMany(models.MomAgenda, { as: "momagendas", foreignKey: "mom_id" });
        Mom.hasMany(models.MomResult, { as: "momresults", foreignKey: "mom_id" });
        Mom.hasMany(models.MomFile, { as: "momfiles", foreignKey: "mom_id" });
    }

    return Mom;
};
