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

@Entity('daily_reconciliations')
@Index('uk_reconciliation_date', ['reconciliationDate'], { unique: true })
@Index('idx_status', ['status'])
export class DailyReconciliation {
  @PrimaryGeneratedColumn({ type: 'bigint', unsigned: true, comment: '对账ID' })
  id: number;

  @Column({ type: 'date', name: 'reconciliation_date', comment: '对账日期' })
  reconciliationDate: Date;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'total_order_amount', comment: '订单总金额' })
  totalOrderAmount: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'total_service_fee', comment: '服务费总额' })
  totalServiceFee: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'total_cashback', comment: '返现总额' })
  totalCashback: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'total_settlement', comment: '结算总额' })
  totalSettlement: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'total_withdraw', comment: '提现总额' })
  totalWithdraw: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'platform_balance_start', comment: '平台期初余额' })
  platformBalanceStart: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0.00, name: 'platform_balance_end', comment: '平台期末余额' })
  platformBalanceEnd: number;

  @Column({ type: 'int', unsigned: true, default: 0, name: 'order_count', comment: '订单数量' })
  orderCount: number;

  @Column({ type: 'int', unsigned: true, default: 0, name: 'settlement_count', comment: '结算单数量' })
  settlementCount: number;

  @Column({ type: 'int', unsigned: true, default: 0, name: 'withdraw_count', comment: '提现单数量' })
  withdrawCount: number;

  @Column({ type: 'enum', enum: ['pending', 'completed', 'failed'], default: 'pending', comment: '对账状态' })
  status: 'pending' | 'completed' | 'failed';

  @Column({ type: 'text', nullable: true, comment: '对账备注' })
  remark: string;

  @Column({ type: 'bigint', unsigned: true, nullable: true, name: 'operator_id', comment: '操作人ID' })
  operatorId: number;

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

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