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

module.exports = (sequelize) => {
  const WorkActivity = sequelize.define(
    "workactivitie",
    {
      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
      activity_date: { type: DataTypes.DATEONLY, allowNull: true },
      work_type: { type: DataTypes.STRING, allowNull: true },

      // fk
      employee_id: {
        type: DataTypes.INTEGER,
        allowNull: true,
      },
    },
    {
      tableName: "workactivities",
      freezeTableName: true,
    }
  );

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

  return WorkActivity;
};
