'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class Inventory 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
       Inventory.belongsTo(models.Store, { foreignKey: 'storeId', as: 'store' });
       Inventory.belongsTo(models.Product, { foreignKey: 'productId', as: 'product' });
        Inventory.belongsTo(models.ProductVariant, { foreignKey: 'productVariantId', as: 'productVariant' });
    }
  }
  Inventory.init({
    productId: DataTypes.INTEGER,
    productVariantId: DataTypes.INTEGER,
    storeId: DataTypes.INTEGER,
    quantityOnHand: DataTypes.INTEGER,
    quantityReserved: DataTypes.INTEGER,
    quantityAvailable: DataTypes.INTEGER,
    lastRestocked: DataTypes.DATE
  }, {
    sequelize,
    modelName: 'Inventory',
  });
  return Inventory;
};