import { Repository, DataSource } from 'typeorm';
import { PreviousNcEntity } from '../entities/previous-nc.entity';
import { PreviousNcrEntryEntity } from '../entities/previous-ncr-entry.entity';
import { PreviousNcRemarkEntity } from '../entities/previous-nc-remark.entity';
import { PreviousNcFinalClosureEntity } from '../entities/previous-nc-final-closure.entity';
import { PreviousNcClientEntity } from '../entities/previous-nc-client.entity';
import { PreviousNcSurveEntity } from '../entities/previous-nc-surve.entity';
import { PreviousNcStandardEntity } from '../entities/previous-nc-standard.entity';
import { PreviousNcUserEntity } from '../entities/previous-nc-user.entity';
import { ListPreviousNcsDto } from '../dto/list-previous-ncs.dto';
import { UpdatePreviousNcDto } from '../dto/update-previous-nc.dto';
import { NcFileStorageService } from './nc-file-storage.service';
import { Readable } from 'stream';
import { NcEmailTemplateService } from './nc-email-template.service';
import { MailsService } from '../../mails/mails.service';
import { PreviousNcPdfService } from './previous-nc-pdf.service';
export interface PreviousNcRowDto {
    id: number;
    source: 'QRS' | 'TQS' | 'NEW';
    company_name: string | null;
    contact_primary: string | null;
    audit_type: string;
    nc_type: string;
    status: string;
    created_by_name: string | null;
    assigned_to_name: string | null;
    uploaded_doc: string | null;
    old_nc_document: string | null;
    created_at: Date;
    entries_count: number;
}
export interface PreviousNcDetailDto {
    nc: PreviousNcEntity & {
        source: 'QRS' | 'TQS' | 'NEW';
        company_code: string | null;
        contact_person: string | null;
        client_email: string | null;
        mobile: string | null;
        location: string | null;
        company_name: string | null;
        auditee_name: string | null;
        audit_date: string | null;
        designation: string | null;
        standard_names: string[];
        created_by_name: string | null;
        assigned_to_name: string | null;
    };
    entries: PreviousNcrEntryEntity[];
    remarks: PreviousNcRemarkEntity[];
    final_closures: PreviousNcFinalClosureEntity[];
}
export interface PreviousNcUserOptionDto {
    name: string;
    count: number;
}
export declare class PreviousNcService {
    private readonly qrsNcRepo;
    private readonly qrsEntryRepo;
    private readonly qrsRemarkRepo;
    private readonly qrsClosureRepo;
    private readonly qrsClientRepo;
    private readonly qrsSurveRepo;
    private readonly qrsStandardRepo;
    private readonly qrsUserRepo;
    private readonly tqsNcRepo;
    private readonly tqsEntryRepo;
    private readonly tqsRemarkRepo;
    private readonly tqsClosureRepo;
    private readonly tqsClientRepo;
    private readonly tqsSurveRepo;
    private readonly tqsStandardRepo;
    private readonly tqsUserRepo;
    private readonly qrsDataSource;
    private readonly tqsDataSource;
    private readonly schemeDb;
    private readonly fileStorage;
    private readonly emailTpl;
    private readonly mailsService;
    private readonly pdfService;
    private readonly logger;
    constructor(qrsNcRepo: Repository<PreviousNcEntity>, qrsEntryRepo: Repository<PreviousNcrEntryEntity>, qrsRemarkRepo: Repository<PreviousNcRemarkEntity>, qrsClosureRepo: Repository<PreviousNcFinalClosureEntity>, qrsClientRepo: Repository<PreviousNcClientEntity>, qrsSurveRepo: Repository<PreviousNcSurveEntity>, qrsStandardRepo: Repository<PreviousNcStandardEntity>, qrsUserRepo: Repository<PreviousNcUserEntity>, tqsNcRepo: Repository<PreviousNcEntity>, tqsEntryRepo: Repository<PreviousNcrEntryEntity>, tqsRemarkRepo: Repository<PreviousNcRemarkEntity>, tqsClosureRepo: Repository<PreviousNcFinalClosureEntity>, tqsClientRepo: Repository<PreviousNcClientEntity>, tqsSurveRepo: Repository<PreviousNcSurveEntity>, tqsStandardRepo: Repository<PreviousNcStandardEntity>, tqsUserRepo: Repository<PreviousNcUserEntity>, qrsDataSource: DataSource, tqsDataSource: DataSource, schemeDb: DataSource, fileStorage: NcFileStorageService, emailTpl: NcEmailTemplateService, mailsService: MailsService, pdfService: PreviousNcPdfService);
    private notifyNcRaised;
    private userHasNcPermission;
    private formatNcrStatement;
    private formatCriteriaClause;
    private escapeHtml;
    private fetchNewNcs;
    private findOneNew;
    createNew(dto: {
        audit_id: number;
        nc_type: string;
        status?: string;
        auditee_name?: string | null;
        auditees?: Array<{
            name: string;
            designation?: string;
        }>;
        follow_up_date?: string | null;
        due_date?: string | null;
        follow_up_notes?: string | null;
        remark?: string | null;
        findings: Array<{
            nc_type?: string;
            ncr_statement: string;
            criteria_clause?: string;
            corrective_action?: string;
            status?: string;
        }>;
    }, currentUserId: number): Promise<{
        ok: true;
        nc_id: number;
        audit_id: number;
        findings_created: number;
    }>;
    sendNcNotificationManual(source: 'QRS' | 'TQS' | 'NEW', ncId: number, dto: {
        send_nc_to_client?: boolean;
        client_to?: string;
        client_cc?: string;
        client_bcc?: string;
        send_to_coord_auditor?: boolean;
        auditor_email?: string;
        coordinator_email?: string;
    }, currentUserId: number): Promise<{
        ok: true;
        sent: string[];
    }>;
    private sourceIdCache;
    resolveSourceUserId(schemeUserId: number, source: 'QRS' | 'TQS'): Promise<number | null>;
    userCanViewAll(userId: number): Promise<boolean>;
    listUsers(): Promise<PreviousNcUserOptionDto[]>;
    auditAssignReport(): Promise<{
        rows: Array<{
            user_id: number;
            auditor: string;
            source: 'QRS' | 'TQS';
            total_assigned: number;
            stage1_uploaded: number;
            stage1_missing: number;
            stage2_uploaded: number;
            stage2_missing: number;
            initial: number;
            surveillance: number;
            recertification: number;
            months: Array<{
                month: string;
                total_assigned: number;
                stage1_uploaded: number;
                stage2_uploaded: number;
                initial: number;
                surveillance: number;
                recertification: number;
            }>;
        }>;
        totals: {
            total_assigned: number;
            stage1_uploaded: number;
            stage1_missing: number;
            stage2_uploaded: number;
            stage2_missing: number;
            initial: number;
            surveillance: number;
            recertification: number;
        };
    }>;
    listPaged(q: ListPreviousNcsDto, currentUserId: number): Promise<{
        rows: PreviousNcRowDto[];
        total: number;
        page: number;
        limit: number;
        totalPages: number;
    }>;
    private fetchFromSource;
    private countEntriesPerNc;
    private shapeRow;
    findOne(source: 'QRS' | 'TQS' | 'NEW', id: number, currentUserId: number): Promise<PreviousNcDetailDto>;
    update(source: 'QRS' | 'TQS' | 'NEW', id: number, dto: UpdatePreviousNcDto, currentUserId: number): Promise<{
        ok: true;
        nc_id: number;
        source: 'QRS' | 'TQS' | 'NEW';
        updated_fields: string[];
        updated_entries: number;
        new_remark_id: number | null;
        new_findings_created: number;
    }>;
    uploadEntryEvidence(source: 'QRS' | 'TQS' | 'NEW', ncId: number, entryId: number, file: Express.Multer.File, currentUserId: number): Promise<{
        ok: true;
        entry_id: number;
        document_path: string;
        filename: string;
        size: number;
        uploaded_at: string;
    }>;
    openEntryFile(source: 'QRS' | 'TQS' | 'NEW', ncId: number, entryId: number, index?: number): Promise<{
        stream: Readable;
        size: number;
        mimeType: string;
        filename: string;
    }>;
    deleteEntryEvidence(source: 'QRS' | 'TQS' | 'NEW', ncId: number, entryId: number, currentUserId: number): Promise<{
        ok: true;
        entry_id: number;
        deleted_file: boolean;
    }>;
    deleteNc(source: 'QRS' | 'TQS' | 'NEW', id: number, currentUserId: number): Promise<{
        ok: true;
        deleted_id: number;
        deleted_entries: number;
    }>;
    deleteEntry(source: 'QRS' | 'TQS' | 'NEW', ncId: number, entryId: number, currentUserId: number): Promise<{
        ok: true;
        entry_id: number;
        deleted_file: boolean;
    }>;
    auditNcStatusReport(currentUserId: number, q?: {
        source?: 'QRS' | 'TQS' | 'All';
        status?: 'Raised' | 'Pending' | 'All';
        date_from?: string;
        date_to?: string;
        search?: string;
        auditor?: string;
        year?: number | string;
        month?: number | string;
    }): Promise<{
        rows: Array<{
            source: 'QRS' | 'TQS';
            audit_kind: 'client' | 'surveillance' | 'recertification';
            audit_id: number;
            company_name: string | null;
            audit_date: string | null;
            auditor_names: string[];
            nc_count: number;
            nc_status: 'NC Raised' | 'NC Pending';
        }>;
        totals: {
            total: number;
            raised: number;
            pending: number;
        };
        can_view_all: boolean;
    }>;
    private resolveStandardNames;
    private fullName;
    draftFinding(nc_type: string, note: string): Promise<any>;
}
