import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, ManyToOne, JoinColumn } from 'typeorm';
import { User } from './user.entity';
import { Coupon } from './coupon.entity';

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

  @Column({ name: 'user_id', type: 'bigint', unsigned: true, comment: '用户ID' })
  userId: number;

  @Column({ name: 'coupon_id', type: 'bigint', unsigned: true, comment: '优惠券ID' })
  couponId: number;

  @Column({ type: 'enum', enum: ['unused', 'used', 'expired'], default: 'unused', comment: '状态' })
  status: 'unused' | 'used' | 'expired';

  @Column({ name: 'order_id', type: 'bigint', unsigned: true, nullable: true, comment: '使用的订单ID' })
  orderId: number;

  @Column({ name: 'used_at', type: 'datetime', nullable: true, comment: '使用时间' })
  usedAt: Date;

  @Column({ name: 'expire_at', type: 'datetime', comment: '过期时间' })
  expireAt: Date;

  @CreateDateColumn({ name: 'received_at', comment: '领取时间' })
  receivedAt: Date;

  @ManyToOne(() => User)
  @JoinColumn({ name: 'user_id' })
  user: User;

  @ManyToOne(() => Coupon)
  @JoinColumn({ name: 'coupon_id' })
  coupon: Coupon;
}
