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

const Coupon = sequelize.define('Coupon', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  code: { type: DataTypes.STRING(50), allowNull: false, unique: true },
  type: { type: DataTypes.ENUM('fixed', 'percentage'), allowNull: false },
  value: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
  minOrderAmount: { type: DataTypes.DECIMAL(10, 2), field: 'min_order_amount' },
  maxDiscountAmount: { type: DataTypes.DECIMAL(10, 2), field: 'max_discount_amount' },
  maxUses: { type: DataTypes.INTEGER, field: 'max_uses' },
  usedCount: { type: DataTypes.INTEGER, defaultValue: 0, field: 'used_count' },
  isActive: { type: DataTypes.BOOLEAN, defaultValue: true, field: 'is_active' },
  startsAt: { type: DataTypes.DATE, field: 'starts_at' },
  expiresAt: { type: DataTypes.DATE, field: 'expires_at' },
  description: { type: DataTypes.TEXT },
}, {
  tableName: 'coupons',
  timestamps: true,
  underscored: true,
});

module.exports = Coupon;
