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

export enum TransactionType {
  DEPOSIT = 'deposit', WITHDRAWAL = 'withdrawal', PURCHASE = 'purchase',
  SALE = 'sale', TRANSFER_IN = 'transfer_in', TRANSFER_OUT = 'transfer_out',
  FEE = 'fee', REFUND = 'refund',
}

@Entity('transactions')
@Index('idx_transactions_wallet', ['walletId'])
@Index('idx_transactions_type', ['type'])
export class Transaction {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column({ name: 'wallet_id', type: 'uuid' }) walletId: string;
  @Column({ type: 'varchar', length: 20 }) type: TransactionType;
  @Column({ type: 'numeric', precision: 20, scale: 8 }) amount: string;
  @Column({ name: 'balance_after', type: 'numeric', precision: 20, scale: 8 }) balanceAfter: string;
  @Column({ type: 'varchar', length: 10, default: 'USD' }) currency: string;
  @Column({ name: 'reference_id', type: 'uuid', nullable: true }) referenceId: string | null;
  @Column({ name: 'reference_type', type: 'varchar', length: 50, nullable: true }) referenceType: string | null;
  @Column({ type: 'text', nullable: true }) description: string | null;
  @Column({ type: 'varchar', length: 20, default: 'completed' }) status: string;
  @CreateDateColumn({ name: 'created_at', type: 'timestamptz' }) createdAt: Date;
}
