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

@Entity('platform_withdrawals')
@Index('uk_withdraw_no', ['withdrawNo'], { unique: true })
@Index('idx_account_id', ['accountId'])
@Index('idx_status', ['status'])
@Index('idx_created_at', ['createdAt'])
export class PlatformWithdrawal {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true, comment: '提现ID' })
  id: number;

  @Column({ type: 'varchar', length: 32, name: 'withdraw_no', comment: '提现单号（全局唯一）' })
  withdrawNo: string;

  @Column({ type: 'bigint', unsigned: true, name: 'account_id', comment: '账户ID' })
  accountId: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, comment: '提现金额' })
  amount: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0, comment: '手续费' })
  fee: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, name: 'actual_amount', comment: '实际到账金额' })
  actualAmount: number;

  @Column({ type: 'varchar', length: 100, name: 'bank_name', comment: '开户银行' })
  bankName: string;

  @Column({ type: 'varchar', length: 50, name: 'bank_account', comment: '银行账号' })
  bankAccount: string;

  @Column({ type: 'varchar', length: 50, name: 'account_name', comment: '账户名' })
  accountName: string;

  @Column({ type: 'enum', enum: ['pending', 'approved', 'rejected', 'paid', 'failed'], default: 'pending', comment: '状态' })
  status: 'pending' | 'approved' | 'rejected' | 'paid' | 'failed';

  @Column({ type: 'varchar', length: 500, nullable: true, name: 'reject_reason', comment: '拒绝原因' })
  rejectReason: string;

  @Column({ type: 'bigint', unsigned: true, nullable: true, name: 'reviewer_id', comment: '审核人ID（超级管理员）' })
  reviewerId: number;

  @Column({ type: 'datetime', nullable: true, name: 'reviewed_at', comment: '审核时间' })
  reviewedAt: Date;

  @Column({ type: 'datetime', nullable: true, name: 'paid_at', comment: '打款时间' })
  paidAt: Date;

  @Column({ type: 'varchar', length: 100, nullable: true, name: 'payment_no', comment: '第三方支付单号' })
  paymentNo: string;

  @Column({ type: 'varchar', length: 500, nullable: true, comment: '备注' })
  remark: string;

  @CreateDateColumn({ type: 'datetime', name: 'created_at', comment: '申请时间' })
  createdAt: Date;

  @UpdateDateColumn({ type: 'datetime', name: 'updated_at', comment: '更新时间' })
  updatedAt: Date;
}
