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

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

      employee_id: { type: DataTypes.INTEGER, allowNull: false, references: { model: "employees", key: "id" } },
      mom_id: { type: DataTypes.INTEGER, allowNull: false, references: { model: "moms", key: "id" } },
    },
    {
      tableName: "momparticipants",
      freezeTableName: true,
    }
  );

  /**
   * Associates the MomParticipant model with other models.
   * @param {object} models - The models to associate with.
   */
  MomParticipant.associate = (models) => {
    /**
     * A MomParticipant belongs to one Mom.
     * @param {object} models - The models to associate with.
     */
    MomParticipant.belongsTo(models.Mom, { as: "mom", foreignKey: "mom_id" });

    /**
     * A MomParticipant belongs to one Employee.
     * @param {object} models - The models to associate with.
     */
    MomParticipant.belongsTo(models.Employee, { as: "employee", foreignKey: "employee_id" });
  }

  return MomParticipant;
};
