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

export type FinancialOperationStatus = 'running' | 'completed' | 'failed';

@Entity('financial_operations')
@Index(['operationId'], { unique: true })
export class FinancialOperation {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'operation_id', type: 'varchar', length: 64, unique: true })
  operationId: string;

  @Column({ type: 'varchar', length: 64 })
  type: string;

  @Column({ type: 'varchar', length: 20, default: 'running' })
  status: FinancialOperationStatus;

  @Column({ name: 'result_json', type: 'text', nullable: true })
  resultJson: string | null;

  @Column({ name: 'error_message', type: 'varchar', length: 500, nullable: true })
  errorMessage: string | null;

  @CreateDateColumn({ name: 'created_at' })
  createdAt: Date;

  @UpdateDateColumn({ name: 'updated_at' })
  updatedAt: Date;
}
