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

  OrderDetails.init({
    ...defaultKeys("order_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,
    },
    order_status: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: 'New',
    },
  }, modelDefaults(sequelize, 'order_details'));
  return OrderDetails;
};