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

module.exports = (sequelize) => {
  const WorkActivityPlanItem = sequelize.define(
    "workactivityplanitem",
    {
      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, defaultValue: true },

      work_activity_plan_id: { type: DataTypes.INTEGER, allowNull: false },
      plan_date: { type: DataTypes.DATEONLY, allowNull: false },
      work_type: { type: DataTypes.STRING(10), allowNull: false },
    },
    {
      tableName: "workactivityplanitems",
      freezeTableName: true,
      timestamps: true,
      createdAt: "createdAt",
      updatedAt: "updatedAt",
    }
  );

  WorkActivityPlanItem.associate = (models) => {
    WorkActivityPlanItem.belongsTo(models.WorkActivityPlan, {
      foreignKey: "work_activity_plan_id",
      as: "workactivityplan",
      onDelete: "CASCADE",
    });
  };

  return WorkActivityPlanItem;
};
