import { Column, CreateDateColumn, Entity, Index, PrimaryGeneratedColumn } from 'typeorm';
import type { ImportRowAction, ImportRowStatus } from '../imports.types';

@Entity('import_rows')
@Index('idx_import_rows_step', ['stepId'])
@Index('idx_import_rows_run_status', ['runId', 'status'])
export class ImportRow {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'run_id', type: 'varchar', length: 36 })
  runId: string;

  @Column({ name: 'step_id', type: 'integer' })
  stepId: number;

  @Column({ name: 'sheet_name', type: 'varchar', length: 200 })
  sheetName: string;

  @Column({ name: 'row_number', type: 'integer' })
  rowNumber: number;

  @Column({ name: 'raw_json', type: 'text' })
  rawJson: string;

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

  @Column({ name: 'match_key', type: 'varchar', length: 200, nullable: true })
  matchKey: string | null;

  @Column({ name: 'action', type: 'varchar', length: 10, nullable: true })
  action: ImportRowAction | null;

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

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

  @Column({ name: 'target_id', type: 'integer', nullable: true })
  targetId: number | null;

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