'use strict';
const { Model } = require('sequelize');
const { defaultKeys, modelDefaults, actionUsers } = require('../sequelize/defaults');
module.exports = (sequelize, DataTypes) => {
  class OrderReturnDetails extends Model {
    static associate(models) {
      actionUsers(OrderReturnDetails, models);
      OrderReturnDetails.belongsTo(models.OrderReturn, {
        targetKey: "return_id",
        foreignKey: "return_id",
        as: "order",
      });
      OrderReturnDetails.belongsTo(models.Product, {
        targetKey: "product_id",
        foreignKey: "product_id",
        as: "product",
      });
      OrderReturnDetails.hasMany(models.OrderDetails, {
        targetKey: "order_detail_id",
        foreignKey: "order_detail_id",
        as: "orderDetails",
      });
    }
  }

  OrderReturnDetails.init({
    ...defaultKeys("return_detail_id"),
    tbl_ref_id: {
      type: DataTypes.STRING,
      allowNull: true,
    },
    price: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    quantity: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    amount: {
      type: DataTypes.STRING,
      allowNull: false,
    },
    type: {
      type: DataTypes.STRING,
      allowNull: false,
    },
  }, modelDefaults(sequelize, 'order_return_details'));
  return OrderReturnDetails;
};