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

  Customer.init({
    ...defaultKeys("customer_id"),
    tbl_ref_id: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    customer_name: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    mobile_number: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    customer_descp: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    active_status: {
      type: DataTypes.BOOLEAN,
      allowNull: false,
      defaultValue: 1,
    },
  }, modelDefaults(sequelize, 'customers'));
  return Customer;
};