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

@Entity('coupons')
@Index('idx_code', ['code'])
@Index('idx_active', ['is_active'])
@Index('idx_validity', ['valid_from', 'valid_to'])
export class Coupon {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ length: 50, unique: true })
  code: string;

  @Column({ length: 255, nullable: true })
  description: string;

  @Column({ type: 'enum', enum: ['percentage', 'fixed'] })
  discount_type: 'percentage' | 'fixed';

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

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

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

  @Column({
    type: 'enum',
    enum: ['plan', 'job_package', 'all'],
    default: 'all',
  })
  applicable_on: 'plan' | 'job_package' | 'all';

  @Column({ type: 'int', nullable: true })
  usage_limit: number;

  @Column({ type: 'int', default: 1 })
  per_user_limit: number;

  @Column({ type: 'datetime' })
  valid_from: Date;

  @Column({ type: 'datetime' })
  valid_to: Date;

  @Column({ default: true })
  is_active: boolean;

  @CreateDateColumn()
  created_at: Date;
}
