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

export enum SettlementStatus { PENDING = 'pending', PROCESSING = 'processing', COMPLETED = 'completed', FAILED = 'failed' }

@Entity('settlements')
export class Settlement {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column({ name: 'trade_id', type: 'uuid' }) tradeId: string;
  @Column({ name: 'buyer_id', type: 'uuid' }) buyerId: string;
  @Column({ name: 'seller_id', type: 'uuid' }) sellerId: string;
  @Column({ type: 'numeric', precision: 20, scale: 8 }) amount: string;
  @Column({ name: 'buyer_fee', type: 'numeric', precision: 20, scale: 8, default: '0' }) buyerFee: string;
  @Column({ name: 'seller_fee', type: 'numeric', precision: 20, scale: 8, default: '0' }) sellerFee: string;
  @Column({ type: 'varchar', length: 10, default: 'USD' }) currency: string;
  @Column({ type: 'varchar', length: 20, default: 'pending' }) status: SettlementStatus;
  @Column({ name: 'settled_at', type: 'timestamptz', nullable: true }) settledAt: Date | null;
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) createdAt: Date;
  @VersionColumn({ default: 1 }) version: number;
}
