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

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

      // main
      workactivity_plan: { type: DataTypes.TEXT, allowNull: true },
      workactivity_result: { type: DataTypes.TEXT, allowNull: true },
      file: { type: DataTypes.STRING, allowNull: true },

      // fk
      workactivity_id: { type: DataTypes.INTEGER, allowNull: false },
    },
    {
      tableName: "workactivityitems",
      freezeTableName: true,
    }
  );

  /**
   * Associates the WorkActivityItem model with other models.
   * @param {object} models - The models to associate with.
   * @description
   */
  WorkActivityItem.associate = (models) => {
    WorkActivityItem.belongsTo(models.WorkActivity, {
      foreignKey: "workactivity_id",
      as: "workactivity",
      onDelete: "CASCADE",
    });
  };

  return WorkActivityItem;
};
