'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class ProductVariant 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
      ProductVariant.belongsTo(models.Product, { foreignKey: 'productId', as: 'product' });
      
      ProductVariant.hasMany(models.StockMovement, { foreignKey: 'productVariantId', as: 'stockmovements' });
      ProductVariant.hasMany(models.Inventory, { foreignKey: 'productVariantId', as: 'inventory' });
    }
  }
  ProductVariant.init({
    productId: DataTypes.INTEGER,
    sku: DataTypes.STRING,
    name: DataTypes.STRING,
    attributes: DataTypes.JSON,
    unitPrice: DataTypes.DECIMAL,
    costPrice: DataTypes.DECIMAL,
    barcode: DataTypes.STRING,
    imageUrl: DataTypes.STRING,
    isActive: DataTypes.BOOLEAN
  }, {
    sequelize,
    modelName: 'ProductVariant',
  });
  return ProductVariant;
};