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

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

            result: { type: DataTypes.TEXT, allowNull: true },
            mom_id: { type: DataTypes.INTEGER, allowNull: true, references: { model: "moms", key: "id" } },
        },
        {
            tableName: "momresults",
            freezeTableName: true,
        }
    );

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

    return MomResult;
};
