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

/**
 * Photos the auditor uploads for a report (products, premises, evidence...).
 *   section_key 'org_brief'   -> shown under "Brief about the organization" (the product pictures of the Word form)
 *   section_key 'audit_brief' -> shown under "Audit brief and facts"
 *   clause_id set             -> shown inside that clause row's evidence cell
 * The file itself lives on disk (storage/auditReportImages/<report_id>/<file_name>).
 */
@Entity({ name: 'audit_report_images' })
export class AuditReportImage {
  @PrimaryGeneratedColumn() id: number;

  @Index() @Column({ type: 'int' }) report_id: number;
  @Column({ type: 'varchar', length: 40, default: 'org_brief' }) section_key: string;
  @Index() @Column({ type: 'int', nullable: true }) clause_id: number | null;

  @Column({ type: 'varchar', length: 300 }) file_name: string;
  @Column({ type: 'varchar', length: 255, default: '' }) original_name: string;
  @Column({ type: 'varchar', length: 60 }) mime: string;
  @Column({ type: 'int', default: 0 }) width: number;
  @Column({ type: 'int', default: 0 }) height: number;
  @Column({ type: 'int', default: 0 }) size_bytes: number;
  @Column({ type: 'varchar', length: 300, default: '' }) caption: string;
  @Column({ type: 'int', default: 0 }) sort_order: number;
  @Column({ type: 'int', nullable: true }) uploaded_by: number | null;

  @CreateDateColumn({ type: 'datetime', precision: 6 }) created_at: Date;
  @UpdateDateColumn({ type: 'datetime', precision: 6 }) updated_at: Date;
}
