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

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

      display_name: { type: DataTypes.TEXT, allowNull: false },
      periode: { type: DataTypes.STRING(50), allowNull: false },
      indicator: { type: DataTypes.TEXT, allowNull: true },
      target: { type: DataTypes.INTEGER, allowNull: true },
      periode_evaluation: { type: DataTypes.STRING(50), allowNull: true },
      calculation_method: { type: DataTypes.STRING(100), allowNull: true },
      score: { type: DataTypes.INTEGER, allowNull: true },
      note: { type: DataTypes.TEXT, allowNull: true },

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

  /**
   * Associates the CallPlan model with other models.
   * @param {object} models - The models to associate with.
   */
  SasaranMutu.associate = (models) => {
    SasaranMutu.belongsTo(models.Department, { foreignKey: "department_id", as: "department" });
  };

  return SasaranMutu;
};
