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

@Entity('coupons')
export class Coupon {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true })
  id: number;

  @Column({ length: 100, comment: '优惠券名称' })
  name: string;

  @Column({ type: 'enum', enum: ['fixed', 'percent'], comment: '类型' })
  type: 'fixed' | 'percent';

  @Column({ type: 'decimal', precision: 10, scale: 2, unsigned: true, comment: '优惠金额/折扣比例' })
  value: number;

  @Column({ name: 'min_amount', type: 'decimal', precision: 10, scale: 2, unsigned: true, default: 0, comment: '最低使用金额' })
  minAmount: number;

  @Column({ name: 'total_count', type: 'int', unsigned: true, default: 0, comment: '发放总量' })
  totalCount: number;

  @Column({ name: 'used_count', type: 'int', unsigned: true, default: 0, comment: '已使用数量' })
  usedCount: number;

  @Column({ name: 'remain_count', type: 'int', unsigned: true, default: 0, comment: '剩余数量' })
  remainCount: number;

  @Column({ name: 'start_date', type: 'date', comment: '生效日期' })
  startDate: string;

  @Column({ name: 'end_date', type: 'date', comment: '失效日期' })
  endDate: string;

  @Column({ type: 'enum', enum: ['platform', 'merchant', 'room'], default: 'platform', comment: '适用范围' })
  scope: 'platform' | 'merchant' | 'room';

  @Column({ name: 'scope_id', type: 'bigint', unsigned: true, nullable: true, comment: '范围关联ID' })
  scopeId: number;

  @Column({ type: 'enum', enum: ['active', 'paused', 'ended'], default: 'active', comment: '状态' })
  status: 'active' | 'paused' | 'ended';

  @Column({ name: 'created_by', type: 'bigint', unsigned: true, nullable: true, comment: '创建人ID' })
  createdBy: number;

  @CreateDateColumn({ name: 'created_at', comment: '创建时间' })
  createdAt: Date;
}
