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

module.exports = (sequelize) => {
    const MomAgenda = sequelize.define(
        "momagenda",
        {
            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 },

            agenda: { type: DataTypes.STRING(100), allowNull: true },
            mom_id: { type: DataTypes.INTEGER, allowNull: true, references: { model: "moms", key: "id" } },
        },
        {
            tableName: "momagendas",
            freezeTableName: true,
        } 
    );

    MomAgenda.associate = (models) => {
        MomAgenda.belongsTo(models.Mom, { foreignKey: "mom_id", as: "mom", onDelete: "CASCADE" });
    }

    return MomAgenda;
};
