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

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

            mom_id: { type: DataTypes.INTEGER, allowNull: false, references: { model: "moms", key: "id" } },
            filename: { type: DataTypes.STRING, allowNull: false },
            path: { type: DataTypes.STRING, allowNull: false },
            size: { type: DataTypes.INTEGER, allowNull: false },
        },
        {
            tableName: "momfiles",
            freezeTableName: true,
        }
    );

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

    return MomFile;
};
