// src/pdf/template-registry.ts
import { join } from 'path';
import * as fs from 'fs';

// __dirname points to dist/pdf after build
const BASE_DIR = join(__dirname, '../certificates/templates');

export const templates = {
  stage1: {
     'scope-summary-report': join(BASE_DIR, 'stage1', 'scope-summary-report.hbs'),
     'audit-meeting': join(BASE_DIR, 'stage1', 'audit-meeting.hbs'),
     'audit-time-plan': join(BASE_DIR, 'stage1', 'audit-time-plan.hbs'),
     'audit-plan': join(BASE_DIR, 'stage1', 'audit-plan.hbs'),
     'initial-inquiry': join(BASE_DIR, 'stage1', 'initial-inquiry.hbs'),
     'form-02-4a-client-sheet': join(BASE_DIR, 'stage1', 'form-02-4a-client-sheet.hbs'),
     'form-02-4b-client-sheet': join(BASE_DIR, 'stage1', 'form-02-4b-client-sheet.hbs'),
     'form-02-4c-client-sheet': join(BASE_DIR, 'stage1', 'form-02-4c-client-sheet.hbs'),
     
     'rules-regulations': join(BASE_DIR, 'stage1', 'rules-regulations.hbs'),
     'qrs_cert': join(BASE_DIR, 'stage1', 'qrs_cert.hbs'),
     'form-04-5-stage-1-audit-plan-blank': join(BASE_DIR, 'stage1', 'Form-04-5-Stage-1-Audit-Plan-blank.hbs'),
     'form-04-5-stage-1-audit-plan-ims': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN (IMS).hbs'),
     'form-04-5-stage-1-audit-plan-qms-9001': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN QMS-9001.hbs'),
     'form-04-5-stage-1-audit-plan-ems-14001': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN EMS-14001.hbs'),
     'form-04-5-stage-1-audit-plan-ohsms-45001': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN-OHSMS-45001.hbs'),
     'form-04-5-stage-1-audit-plan-qms-ems': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN-QMS-EMS.hbs'),
     'form-04-5-stage-1-audit-plan-qms-ohs': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN-QMS-OHS.hbs'),
     'form-04-5-stage-1-audit-plan-ems-ohsm': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN-EMS-OHSM.hbs'),
     'form-04-5-stage-1-audit-plan-IMS(qms,ems,oh&s)': join(BASE_DIR, 'stage1', 'Form 04-5 STAGE 1 AUDIT PLAN-IMS(QMS,EMS,OHSM).hbs'),
 
     'final_company_info_letter' : join(BASE_DIR, 'stage1','final-company-information-letter.hbs'),
     
   },
   stage2: {
     'form-04-5-stage-2-audit-plan-blank': join(BASE_DIR, 'stage2', 'Form-04-5-Stage-2-Audit-Plan-blank.hbs'),
     'form-04-5-stage-2-audit-plan-qms-9001': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN QMS-9001.hbs'),
     'form-04-5-stage-2-audit-plan-ems-14001': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN EMS-14001.hbs'),
     'form-04-5-stage-2-audit-plan-ohsms-45001': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN-OHSMS-45001.hbs'),
     'form-04-5-stage-2-audit-plan-qms-ems': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN-QMS-EMS.hbs'),
     'form-04-5-stage-2-audit-plan-qms-ohs': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN-QMS-OHS.hbs'),
     'form-04-5-stage-2-audit-plan-ems-ohsm': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN-EMS-OHSM.hbs'),
     'form-04-5-stage-2-audit-plan-IMS(qms,ems,oh&s)': join(BASE_DIR, 'stage2', 'Form 04-5 STAGE 2 AUDIT PLAN-IMS(QMS,EMS,OHSM).hbs'),
     'form 07-2-3-recommendation': join(BASE_DIR, 'stage2', 'Form 07-2-3 RECOMMENDATION.hbs'),
     //stage 2
     // 'stage-2-audit-plan-new-14001': join(BASE_DIR, 'stage2', 'STAGE 2 AUDIT PLAN NEW 14001.hbs'),
     // 'stage-2-audit-plan-new-45001': join(BASE_DIR, 'stage2', 'STAGE 2 AUDIT PLAN NEW 45001.hbs'),
     // 'stage-2-audit-plan-new-ims': join(BASE_DIR, 'stage2', 'STAGE 2 AUDIT PLAN NEW IMS.hbs'),
     // 'stage-2-audit-plan-new-qms': join(BASE_DIR, 'stage2', 'STAGE 2 AUDIT PLAN NEW QMS.hbs'),
     'stage-2-certification-requirement-decission-sheet': join(BASE_DIR, 'stage2', 'STAGE 2 Certification Requirement & Decision Sheet.hbs'),
     'stage-2-audit-objective-checklist': join(BASE_DIR, 'stage2', 'STAGE 2 FORM 04-2-2 AUDIT OBJECTIVE CHECKLIST.hbs'),
     'stage-2-surv-plan-qms,ems & 45001': join(BASE_DIR, 'stage2', 'STAGE 2 Form 04-8-5I SURV PLAN QMS, EMS & 45001.hbs'),
     'stage-2-ISO 9001,14001,45001-checklist': join(BASE_DIR, 'stage2', 'STAGE 2 Form ISO 9001,14001,45001 CHECKLIST.hbs'),
 
     // 'scope-summary-report': join(BASE_DIR, 'stage2', 'scope-summary-report.hbs'),
     'audit-meeting': join(BASE_DIR, 'stage2', 'audit-meeting.hbs'),
     'audit-time-plan': join(BASE_DIR, 'stage2', 'audit-time-plan.hbs'),
     'audit-plan': join(BASE_DIR, 'stage2', 'audit-plan.hbs'),
    //  'initial-inquiry': join(BASE_DIR, 'stage2', 'initial-inquiry.hbs'),
    //  'form-02-4a-client-sheet': join(BASE_DIR, 'stage2', 'form-02-4a-client-sheet.hbs'),
    //  'form-02-4b-client-sheet': join(BASE_DIR, 'stage2', 'form-02-4b-client-sheet.hbs'),
     'rules-regulations': join(BASE_DIR, 'stage2', 'rules-regulations.hbs'),
   },
   
  certificates: {
    qrs_certs_iso: join(BASE_DIR, 'qrs_certs_iso.hbs'),
    qrs_certificate_iso: join(BASE_DIR, 'qrs_certificate_iso.hbs'),
    qrs_certificate_iso9001: join(BASE_DIR, 'qrs_certificate_iso9001.hbs'),
    qrs_certificate_iso14001: join(BASE_DIR, 'qrs_certificate_iso14001.hbs'),
    qrs_certificate_iso22000: join(BASE_DIR, 'qrs_certificate_iso22000.hbs'),
    qrs_certificate_iso45001: join(BASE_DIR, 'qrs_certificate_iso45001.hbs'),
    qrs_certificate_iso22301: join(BASE_DIR, 'qrs_certificate_iso22301.hbs'),
    qrs_certificate_iso27001: join(BASE_DIR, 'qrs_certificate_iso27001.hbs'),
    qrs_certificate_iso50001: join(BASE_DIR, 'qrs_certificate_iso50001.hbs'),
    qrs_certificate_isoGMP: join(BASE_DIR, 'qrs_certificate_isoGMP.hbs'),
    qrs_certificate_isoHACCP: join(BASE_DIR, 'qrs_certificate_isoHACCP.hbs'),
    qrs_certificate_isohalal: join(BASE_DIR, 'qrs_certificate_isohalal.hbs'),
  },
};

// Optional: log to debug on startup
Object.entries(templates.certificates).forEach(([key, value]) => {
  console.log('[PDF Template]', key, value, fs.existsSync(value) ? '✅ exists' : '❌ missing');
});
