import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  CreateDateColumn,
  Index,
  Unique,
} from 'typeorm';

@Entity('coupon_redemptions')
@Unique('uq_coupon_user', ['coupon_id', 'user_id'])
@Index('idx_coupon', ['coupon_id'])
@Index('idx_user', ['user_id'])
@Index('idx_payment', ['payment_id'])
export class CouponRedemption {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ type: 'bigint', unsigned: true })
  coupon_id: number;

  @Column({ type: 'int' })
  user_id: number;

  @Column({ type: 'bigint', unsigned: true, nullable: true })
  payment_id: number;

  @Column({ type: 'decimal', precision: 10, scale: 2 })
  discount_amount: number;

  @CreateDateColumn()
  redeemed_at: Date;
}
