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

const OrderItem = sequelize.define('OrderItem', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  orderId: { type: DataTypes.INTEGER, allowNull: false, field: 'order_id' },
  productId: { type: DataTypes.INTEGER, allowNull: false, field: 'product_id' },
  productName: { type: DataTypes.STRING(200), field: 'product_name' },
  productSku: { type: DataTypes.STRING(50), field: 'product_sku' },
  variantInfo: { type: DataTypes.STRING(100), field: 'variant_info' },
  quantity: { type: DataTypes.INTEGER, defaultValue: 1 },
  unitPrice: { type: DataTypes.DECIMAL(10, 2), field: 'unit_price' },
  total: { type: DataTypes.DECIMAL(10, 2) },
  imageUrl: { type: DataTypes.STRING, field: 'image_url' },
}, {
  tableName: 'order_items',
  timestamps: true,
  underscored: true,
});

module.exports = OrderItem;
