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

@Entity('import_steps')
@Index('idx_import_steps_run_key', ['runId', 'stepKey'])
export class ImportStep {
  @PrimaryGeneratedColumn()
  id: number;

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

  @Column({ name: 'step_key', type: 'varchar', length: 20 })
  stepKey: ImportStepKey;

  /** Serialized string[] of sheet names assigned to this stage. */
  @Column({ name: 'sheets_json', type: 'text' })
  sheetsJson: string;

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

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

  /** Serialized StepPreviewSummary of the last commit. */
  @Column({ name: 'summary_json', type: 'text', nullable: true })
  summaryJson: string | null;

  @Column({ name: 'committed_at', type: 'datetime', nullable: true })
  committedAt: Date | null;

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