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

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

  @Column({ type: 'varchar', length: 50, comment: '账户名称（如：SYSTEM_MAIN）' })
  account_name: string;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0, comment: '可用余额（total_income - total_refund - total_withdrawn）' })
  balance: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0, comment: '累计收入（用户实付总额）' })
  total_income: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0, comment: '累计退款' })
  total_refund: number;

  @Column({ type: 'decimal', precision: 12, scale: 2, default: 0, comment: '累计提现（所有提现）' })
  total_withdrawn: number;

  @VersionColumn({ comment: '乐观锁版本号' })
  version: number;

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

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

  @UpdateDateColumn({ comment: '更新时间' })
  updated_at: Date;
}
