import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, Index } from 'typeorm';
import type { StageType } from './audit-report.entity';

@Entity({ name: 'report_templates' })
export class ReportTemplate {
  @PrimaryGeneratedColumn() id: number;
  @Column({ type: 'varchar', length: 60 }) code: string;
  @Column({ type: 'varchar', length: 200 }) name: string;

  /** null = applies to any standard / any stage. The most specific active row wins. */
  @Index() @Column({ type: 'int', nullable: true }) standard_id: number | null;
  @Column({ type: 'enum', enum: ['stage1', 'stage2', 'surveillance', 'recert'], nullable: true })
  stage_type: StageType | null;

  @Column({ type: 'varchar', length: 200, default: 'form-04-2a.hbs' }) hbs_file: string;
  @Column({ type: 'varchar', length: 40, default: 'Form 04-2a' }) form_no: string;
  @Column({ type: 'varchar', length: 20, default: '01' }) issue: string;
  @Column({ type: 'varchar', length: 20, default: '04' }) rev: string;
  @Column({ type: 'varchar', length: 20, default: '01-08-2026' }) effective_date: string;
  @Column({ type: 'tinyint', width: 1, default: 1 }) is_active: boolean;

  @CreateDateColumn() created_at: Date;
  @UpdateDateColumn() updated_at: Date;
}
