'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class PurchaseOrderItem extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      // define association here
      PurchaseOrderItem.belongsTo(models.PurchaseOrder, { foreignKey: 'purchaseOrderId', as: 'purchaseOrder' });
      PurchaseOrderItem.belongsTo(models.Product, { foreignKey: 'productId', as: 'product' });
      PurchaseOrderItem.belongsTo(models.ProductVariant, { foreignKey: 'productVariantId', as: 'productVariant' });
    }
  }
  PurchaseOrderItem.init({
    purchaseOrderId: DataTypes.INTEGER,
    productId: DataTypes.INTEGER,
    productVariantId: DataTypes.INTEGER,
    quantity: DataTypes.INTEGER,
    unitCost: DataTypes.DECIMAL,
    totalCost: DataTypes.DECIMAL,
    receivedQuantity: DataTypes.INTEGER
  }, {
    sequelize,
    modelName: 'PurchaseOrderItem',
  });
  return PurchaseOrderItem;
};