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

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

      status: { type: DataTypes.STRING(100), allowNull: false },
      progress: { type: DataTypes.STRING(100), allowNull: true },
      note: { type: DataTypes.TEXT, allowNull: true },
      chat: { type: DataTypes.JSON, allowNull: true },

      counterpart_note: { type: DataTypes.TEXT, allowNull: true },
      owner_note: { type: DataTypes.TEXT, allowNull: true },

      //fk
      workplanmonitorchild_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "workplanmonitorchilds",
          key: "id",
        },
      },
    },
    {
      tableName: "workplanmonitoractivitychilds",
      freezeTableName: true,
    }
  );

  /**
   * Associates the WorkplanMonitorActivityChild model with other models.
   * @param {object} models - The models to associate with.
   * @description
   *   - A WorkplanMonitorActivityChild belongs to a WorkplanMonitor.
   */
  WorkplanMonitorActivityChild.associate = (models) => {
    /**
     * Associates the WorkplanMonitorActivityChild model with the WorkplanMonitorChild model.
     * A WorkplanMonitorActivityChild belongs to a WorkplanMonitorChild.
     * @param {object} models - The models to associate with.
     */
    WorkplanMonitorActivityChild.belongsTo(models.WorkplanMonitorChild, {
      foreignKey: "workplanmonitorchild_id",
      as: "workplanmonitorchild",
    });
  };

  return WorkplanMonitorActivityChild;
};
