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

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

      accomodation_rate: { type: DataTypes.DECIMAL, allowNull: true }, // penginapan perhari
      daily_meal_rate: { type: DataTypes.DECIMAL, allowNull: true }, // makan perhari
      daily_operational_rate: { type: DataTypes.DECIMAL, allowNull: true }, // operasional perhari
      group_meal_rate: { type: DataTypes.DECIMAL, allowNull: true }, // makan bersama peorang
      effective_date: { type: DataTypes.DATE, allowNull: true },
      expiry_date: { type: DataTypes.DATE, allowNull: true },

      // fk
      designation_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: "designations",
          key: "id",
        },
      },

      company_id: {
        type: DataTypes.INTEGER,
        allowNull: false,
      },
  
    },
    {
      tableName: "travelcostrates",
      freezeTableName: true,
    }
  );

  /**
   * Associates the DoucmentGroup model with other models.
   * @param {object} models - The models to associate with.
   */
  TravelCostRate.associate = (models) => {
    TravelCostRate.belongsTo(models.Designation, { foreignKey: "designation_id", as: "designation" });
    TravelCostRate.belongsTo(models.Company, { foreignKey: "company_id", as: "company" });
  };

  return TravelCostRate;
};
