const Sequelize = require("sequelize");
const sequelizeConnect = require("../connection/db");
const Products = require("./Products");

const InventoryTransferDetails = sequelizeConnect.define(
  "inventory_transfer_details",
  {
    id: {
      type: Sequelize.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
    },
    inventory_transfer_id: {
      type: Sequelize.BIGINT,
      allowNull: false,
    },
    source_product_id: {
      type: Sequelize.BIGINT,
      allowNull: true,
    },
    target_product_id: {
      type: Sequelize.BIGINT,
      allowNull: true,
    },
    quantity: {
      type: Sequelize.DECIMAL(10, 2),
      allowNull: true,
    },
    createdAt: {
      type: Sequelize.DATE,
      allowNull: false,
    },
    updatedAt: {
      type: Sequelize.DATE,
      allowNull: false,
    },
  },
  {
    tableName: "inventory_transfer_details",
    timestamps: true,
  }
);

InventoryTransferDetails.belongsTo(Products, {
  foreignKey: "source_product_id",
  as: "source_product"
})
InventoryTransferDetails.belongsTo(Products, {
  foreignKey: "target_product_id",
  as: "target_product"
})

module.exports = InventoryTransferDetails;
