import { IsEnum, IsObject, IsOptional, IsString, Matches } from 'class-validator';
import type { Conclusion, Stage1Recommendation } from '../entities/audit-report.entity';

export class UpdateHeaderDto {
  /**
   * Field overrides, e.g. { employees: '16', man_days: '2', multisite: 'no', scope: '...' }.
   * Keys are free; the renderer reads: org.* and team.* fields listed in report-builder.service.ts (EDITABLE_FIELDS).
   * Send a key with null to remove the override and fall back to the CRM value.
   */
  @IsOptional() @IsObject()
  fields?: Record<string, string | null>;

  @IsOptional() @IsEnum(['complies', 'minor_nc', 'major_nc', 'not_recommended'])
  conclusion?: Conclusion | null;

  @IsOptional() @IsEnum(['proceed', 'hold', 'repeat_stage1'])
  recommendation?: Stage1Recommendation | null;

  @IsOptional() @IsString() @Matches(/^\d{4}-\d{2}-\d{2}$/, { message: 'next_audit_date must be YYYY-MM-DD' })
  next_audit_date?: string | null;

  /**
   * Ticks and small answers: { declarations: ['d1','d4'], attachments: ['a1'], mark_use: 'm1',
   * mark_use_nc_no: 'NC-12', change_detail: { man_days_adequate: 'yes', scope_change: { value: 'yes', note: '...' } },
   * observations_text: '...' }
   */
  @IsOptional() @IsObject()
  extras?: Record<string, any>;
}
