'use strict';
const { Model } = require('sequelize');
const { defaultKeys, modelDefaults, actionUsers } = require('../sequelize/defaults');
module.exports = (sequelize, DataTypes) => {
  class OrderReturn extends Model {
    static associate(models) {
      actionUsers(OrderReturn, models);
      OrderReturn.belongsTo(models.Branch, {
        targetKey: "branch_id",
        foreignKey: "branch_id",
        as: "branch",
      });
      OrderReturn.belongsTo(models.Order, {
        targetKey: "order_id",
        foreignKey: "order_id",
        as: "order",
      });
      OrderReturn.hasMany(models.OrderReturnDetails, {
        sourceKey: "return_id",
        foreignKey: "return_id",
        as: "orderReturnDetails",
      }); 
    }
  }

  OrderReturn.init({
    ...defaultKeys("return_id"),
    tbl_ref_id: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    return_date: {
      type: DataTypes.DATEONLY,
      allowNull: false,
    },
    total_amount: {
      type: DataTypes.DECIMAL(10, 2),
      allowNull: false,
    },
  }, modelDefaults(sequelize, 'order_return'));
  return OrderReturn;
};