import { DataSource, Repository } from 'typeorm';
import { AuditReport, ReportStatus, StageType } from '../entities/audit-report.entity';
import { AuditReportClause } from '../entities/audit-report-clause.entity';
import { AuditReportImage } from '../entities/audit-report-image.entity';
import { RichBlock } from './rich-text.util';
import { AuditReportSection } from '../entities/audit-report-section.entity';
import { AuditReportAttendance } from '../entities/audit-report-attendance.entity';
import { ClauseLibrary } from '../entities/clause-library.entity';
import { ReportTemplate } from '../entities/report-template.entity';
import { CreateReportDto } from '../dto/create-report.dto';
import { UpdateHeaderDto } from '../dto/update-header.dto';
import { UpsertClauseDto, BulkClausesDto } from '../dto/upsert-clause.dto';
import { AttendeeDto } from '../dto/section-and-attendance.dto';
import { RaiseNcDto } from '../dto/workflow.dto';
import { PreviousNcService } from '../../previous-nc/services/previous-nc.service';
export declare const EDITABLE_FIELDS: readonly ["name", "address", "site_address", "employees", "emails", "contact_person", "telephone", "email", "multisite", "scope", "cert_no", "ea_code", "accreditation", "lead_auditor", "auditors", "technical_expert", "man_days", "audit_date"];
export declare const toDMY: (v: any) => string;
export declare class ReportBuilderService {
    private readonly reports;
    private readonly clauses;
    private readonly sections;
    private readonly images;
    private readonly attendance;
    private readonly library;
    private readonly templates;
    private readonly db;
    private readonly nc;
    private readonly logger;
    constructor(reports: Repository<AuditReport>, clauses: Repository<AuditReportClause>, sections: Repository<AuditReportSection>, images: Repository<AuditReportImage>, attendance: Repository<AuditReportAttendance>, library: Repository<ClauseLibrary>, templates: Repository<ReportTemplate>, db: DataSource, nc: PreviousNcService);
    private readonly SUPER_ADMIN_IDS;
    private readonly norm;
    private userScope;
    canApprove(userId: number, companyId?: number): Promise<boolean>;
    canViewAll(userId: number): Promise<boolean>;
    assertAccess(report: AuditReport, userId: number): Promise<void>;
    private rowAuditorIds;
    private assertEditable;
    getReportOrFail(id: number): Promise<AuditReport>;
    loadForWrite(id: number, userId: number): Promise<AuditReport>;
    private loadUserNames;
    private sanitizeHidden;
    private ensureStandardIds;
    private standardsForEditor;
    rowStandards(rowId: number): Promise<{
        id: number;
        name: string;
        title: string;
    }[]>;
    context(rowId: number, userId: number): Promise<{
        audit: any;
        suggested_stage_type: StageType | null;
        standards: {
            id: number;
            name: string;
            title: string;
        }[];
        can_combine: boolean;
        reports: any[];
    }>;
    loadCrm(rowId: number, standardId: number): Promise<{
        row: any;
        company: any;
        standard_name: string;
        standard_title: string;
        stage_guess: StageType | null;
        fields: Record<string, string>;
        auditees: {
            name: string;
            designation: string;
        }[];
    }>;
    private inferStage;
    private resolveTemplate;
    private libraryFor;
    create(dto: CreateReportDto, userId: number): Promise<{
        report: {
            id: number;
            report_no: string | null;
            audit_schedule_row_id: number;
            company_id: number;
            standard_id: number;
            is_combined: boolean;
            standard_label: string;
            all_standards: {
                id: number;
                name: string;
                title: string;
            }[];
            stage_type: StageType;
            stage_label: string;
            status: ReportStatus;
            conclusion: import("../entities/audit-report.entity").Conclusion | null;
            recommendation: import("../entities/audit-report.entity").Stage1Recommendation | null;
            next_audit_date: string | null;
            version: number;
            return_reason: string | null;
            has_pdf: boolean;
            submitted_at: Date | null;
            approved_at: Date | null;
            crm_refreshed_at: any;
        };
        fields: Record<string, string>;
        crm_fields: any;
        overridden: string[];
        extras: Record<string, any>;
        sections: {
            key: string;
            label: string;
            body: string;
        }[];
        clauses: AuditReportClause[];
        attendance: AuditReportAttendance[];
        client_documents: any;
        ncs: any;
        options: {
            conclusion: {
                key: import("../entities/audit-report.entity").Conclusion;
                text: string;
            }[];
            stage1_recommendation: {
                key: import("../entities/audit-report.entity").Stage1Recommendation;
                text: string;
            }[];
            declarations: {
                key: string;
                text: string;
            }[];
            attachments: import("../report.standards").AttachmentItem[];
            mark_use: {
                key: string;
                text: string;
            }[];
            change_detail: {
                key: string;
                label: string;
                kind: "yesno" | "nonespecify";
            }[];
            editable_fields: readonly ["name", "address", "site_address", "employees", "emails", "contact_person", "telephone", "email", "multisite", "scope", "cert_no", "ea_code", "accreditation", "lead_auditor", "auditors", "technical_expert", "man_days", "audit_date"];
        };
        permissions: {
            can_edit: boolean;
            can_approve: boolean;
        };
    }>;
    updateHeader(id: number, dto: UpdateHeaderDto, userId: number): Promise<{
        ok: boolean;
    }>;
    private clauseOrFail;
    upsertClause(reportId: number, clauseId: number, dto: UpsertClauseDto, userId: number): Promise<AuditReportClause>;
    bulkClauses(reportId: number, dto: BulkClausesDto, userId: number): Promise<{
        ok: boolean;
        saved: number;
    }>;
    upsertSection(reportId: number, key: string, body: string, userId: number): Promise<{
        ok: boolean;
    }>;
    setAttendance(reportId: number, attendees: AttendeeDto[], userId: number): Promise<{
        ok: boolean;
        count: number;
    }>;
    refreshFromCrm(reportId: number, userId: number): Promise<{
        ok: boolean;
        changed: {
            field: string;
            from: string;
            to: string;
            overridden_by_auditor: boolean;
        }[];
    }>;
    raiseNc(reportId: number, clauseId: number, dto: RaiseNcDto, userId: number): Promise<{
        ok: boolean;
        nc_id: number;
        ncr_entry_id: number | null;
        reused_existing_nc: boolean;
    }>;
    list(q: {
        status?: string;
        stage_type?: string;
        standard_id?: number;
        company_id?: number;
        search?: string;
        page?: number;
        limit?: number;
    }, userId: number): Promise<{
        rows: any;
        total: number;
        page: number;
        limit: number;
        totalPages: number;
    }>;
    byAudit(rowId: number, userId: number): Promise<any[]>;
    private clientDocuments;
    loadNcs(rowId: number): Promise<any>;
    private mergedFields;
    getEditorModel(id: number, userId: number): Promise<{
        report: {
            id: number;
            report_no: string | null;
            audit_schedule_row_id: number;
            company_id: number;
            standard_id: number;
            is_combined: boolean;
            standard_label: string;
            all_standards: {
                id: number;
                name: string;
                title: string;
            }[];
            stage_type: StageType;
            stage_label: string;
            status: ReportStatus;
            conclusion: import("../entities/audit-report.entity").Conclusion | null;
            recommendation: import("../entities/audit-report.entity").Stage1Recommendation | null;
            next_audit_date: string | null;
            version: number;
            return_reason: string | null;
            has_pdf: boolean;
            submitted_at: Date | null;
            approved_at: Date | null;
            crm_refreshed_at: any;
        };
        fields: Record<string, string>;
        crm_fields: any;
        overridden: string[];
        extras: Record<string, any>;
        sections: {
            key: string;
            label: string;
            body: string;
        }[];
        clauses: AuditReportClause[];
        attendance: AuditReportAttendance[];
        client_documents: any;
        ncs: any;
        options: {
            conclusion: {
                key: import("../entities/audit-report.entity").Conclusion;
                text: string;
            }[];
            stage1_recommendation: {
                key: import("../entities/audit-report.entity").Stage1Recommendation;
                text: string;
            }[];
            declarations: {
                key: string;
                text: string;
            }[];
            attachments: import("../report.standards").AttachmentItem[];
            mark_use: {
                key: string;
                text: string;
            }[];
            change_detail: {
                key: string;
                label: string;
                kind: "yesno" | "nonespecify";
            }[];
            editable_fields: readonly ["name", "address", "site_address", "employees", "emails", "contact_person", "telephone", "email", "multisite", "scope", "cert_no", "ea_code", "accreditation", "lead_auditor", "auditors", "technical_expert", "man_days", "audit_date"];
        };
        permissions: {
            can_edit: boolean;
            can_approve: boolean;
        };
    }>;
    buildViewModel(id: number): Promise<{
        meta: {
            report_no: string;
            stage_type: StageType;
            stage_label: string;
            is_stage1: boolean;
            status: ReportStatus;
            draft: boolean;
            version: number;
            standard_name: string;
            form_no: string;
            issue: string;
            rev: string;
            effective_date: string;
            form_subtitle: string;
            report_title: string;
            report_title_line2: string;
            docbox_name: string;
            boxes_custom: boolean;
            audit_type_boxes: import("../report.standards").AuditTypeBox[];
        };
        n: {
            org: number;
            team: number;
            change: number;
            cats: number;
            disc: number;
            brief: number;
            attend: number;
            auditBrief: number;
            checklist: number;
            summary: number;
            decl: number;
            rec: number;
            perf?: undefined;
            risk?: undefined;
            feedback?: undefined;
            statutory?: undefined;
            mark?: undefined;
            effectiveness?: undefined;
        } | {
            org: number;
            team: number;
            change: number;
            cats: number;
            disc: number;
            brief: number;
            attend: number;
            auditBrief: number;
            checklist: number;
            perf: number;
            risk: number;
            feedback: number;
            statutory: number;
            mark: number;
            effectiveness: number;
            summary: number;
            decl: number;
            rec?: undefined;
        };
        cover: {
            company: string;
            standard_name: string;
            standard_main: string;
            standard_first: string;
            standard_rest: string;
            standard_sub: string;
            multi: boolean;
            standards: {
                main: string;
                sub: string;
            }[];
            ims_columns: import("../report.standards").CoverColumn[];
            accreditation_ascb: boolean;
            accreditation_other: boolean;
            accreditation: string;
        };
        conclusion_options: {
            text: string;
            on: boolean;
        }[];
        org: {
            multisite_yes: boolean;
            multisite_no: boolean;
        };
        change_detail: ({
            label: string;
            yesno: boolean;
            yes: boolean;
            no: boolean;
            none?: undefined;
            note?: undefined;
        } | {
            label: string;
            yesno: boolean;
            none: boolean;
            yes: boolean;
            note: string;
            no?: undefined;
        })[];
        categories: {
            category: string;
            classification: string;
            definition: string;
        }[];
        labels: import("../report.standards").StandardLabels;
        theme: import("../report.standards").ReportTheme;
        system_short: string;
        system_long: string;
        disclaimer: string;
        confidentiality: string;
        sections: {
            objective: string[];
            criteria: string[];
            org_brief: string[];
            audit_brief: string[];
            prev_nc: string[];
            effectiveness: string[];
            improvement_comments: string[];
        };
        sections_rich: {
            objective: RichBlock[];
            criteria: RichBlock[];
            org_brief: RichBlock[];
            audit_brief: RichBlock[];
            prev_nc: RichBlock[];
            effectiveness: RichBlock[];
            improvement_comments: RichBlock[];
        };
        attendance: {
            name: string;
            designation: string;
            signature_path: string;
        }[];
        images: Record<string, any[]>;
        clause_groups: {
            heading: string;
            rows: ReturnType<(c: AuditReportClause) => {
                images: any[];
                docs: string[];
                evidence: RichBlock[];
                nc_ref: string;
                id: number;
                label: string;
                code: string;
                requirement: string;
                C: boolean;
                NC: boolean;
                OFI: boolean;
                NA: boolean;
            }>[];
        }[];
        perf_groups: {
            heading: string;
            rows: ReturnType<(c: AuditReportClause) => {
                images: any[];
                docs: string[];
                evidence: RichBlock[];
                nc_ref: string;
                id: number;
                label: string;
                code: string;
                requirement: string;
                C: boolean;
                NC: boolean;
                OFI: boolean;
                NA: boolean;
            }>[];
        }[];
        risk_rows: {
            images: any[];
            docs: string[];
            evidence: RichBlock[];
            nc_ref: string;
            id: number;
            label: string;
            code: string;
            requirement: string;
            C: boolean;
            NC: boolean;
            OFI: boolean;
            NA: boolean;
        }[];
        feedback_rows: {
            images: any[];
            docs: string[];
            evidence: RichBlock[];
            nc_ref: string;
            id: number;
            label: string;
            code: string;
            requirement: string;
            C: boolean;
            NC: boolean;
            OFI: boolean;
            NA: boolean;
        }[];
        statutory_rows: {
            images: any[];
            docs: string[];
            evidence: RichBlock[];
            nc_ref: string;
            id: number;
            label: string;
            code: string;
            requirement: string;
            C: boolean;
            NC: boolean;
            OFI: boolean;
            NA: boolean;
        }[];
        mark_use: {
            text: string;
            on: boolean;
        }[];
        mark_use_nc_no: string;
        nc_rows: {
            no: number;
            clause: string;
            type: string;
            statement: string[];
            corrective_action: string;
        }[];
        nc_counts: {
            no: number;
            component: string;
            major: number;
            minor: number;
            obs: number;
        }[];
        nc_counts_fixed: boolean;
        nc_totals: {
            major: number;
            minor: number;
            obs: number;
        };
        declarations: {
            text: string;
            on: boolean;
        }[];
        attachments: {
            text: string;
            heading: boolean;
            on: boolean;
        }[];
        recommendation_options: {
            text: string;
            on: boolean;
        }[];
        next_audit_date: string;
        improvement: {
            modification_required: boolean;
            no_action: boolean;
        };
        lead_auditor: string;
        generated_on: string;
    }>;
}
