'use strict';
const { Model } = require('sequelize');
const { defaultKeys, modelDefaults, actionUsers } = require('../sequelize/defaults');
module.exports = (sequelize, DataTypes) => {
  class AreaAllotment extends Model {
    static associate(models) {
      actionUsers(AreaAllotment, models);
      AreaAllotment.belongsTo(models.Branch, {
        targetKey: "branch_id",
        foreignKey: "branch_id",
        as: "branches",
      });
      AreaAllotment.belongsTo(models.Area, {
        targetKey: "area_id",
        foreignKey: "area_id",
        as: "area",
      });
    }
  }

  AreaAllotment.init({
    ...defaultKeys("allotment_id"),
    tbl_ref_id: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    day: {
      type: DataTypes.ENUM(["MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY", "SUNDAY"]),
      unique: true,
      allowNull: false,
    },
    allotment_descp: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    active_status: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 1,
    },
  }, modelDefaults(sequelize, 'area_allotments'));
  return AreaAllotment;
};