const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const Product = sequelize.define('Product', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  name: { type: DataTypes.STRING(200), allowNull: false },
  slug: { type: DataTypes.STRING(200), allowNull: false, unique: true },
  description: { type: DataTypes.TEXT },
  shortDescription: { type: DataTypes.TEXT, field: 'short_description' },
  price: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
  comparePrice: { type: DataTypes.DECIMAL(10, 2), field: 'compare_price' },
  costPrice: { type: DataTypes.DECIMAL(10, 2), field: 'cost_price' },
  sku: { type: DataTypes.STRING(50), unique: true },
  barcode: { type: DataTypes.STRING(50) },
  stockQuantity: { type: DataTypes.INTEGER, defaultValue: 0, field: 'stock_quantity' },
  lowStockThreshold: { type: DataTypes.INTEGER, defaultValue: 5, field: 'low_stock_threshold' },
  weight: { type: DataTypes.DECIMAL(10, 2) },
  categoryId: { type: DataTypes.INTEGER, field: 'category_id' },
  isFeatured: { type: DataTypes.BOOLEAN, defaultValue: false, field: 'is_featured' },
  isActive: { type: DataTypes.BOOLEAN, defaultValue: true, field: 'is_active' },
  metaTitle: { type: DataTypes.STRING(200), field: 'meta_title' },
  metaDescription: { type: DataTypes.TEXT, field: 'meta_description' },
}, {
  tableName: 'products',
  timestamps: true,
  underscored: true,
});

module.exports = Product;
