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

  Area.init({
    ...defaultKeys("area_id"),
    tbl_ref_id: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    area_name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    area_descp: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    active_status: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 1,
    },
  }, modelDefaults(sequelize, 'areas'));
  return Area;
};