/**
 * ProvenanceExporter - Export provenance records in JSON, W3C PROV-JSON, and CSV
 *
 * Constitution Compliance:
 * - CP-001: Complete provenance chain for every data item
 * - CP-003: SHA-256 content hashing
 * - CP-005: Full reproducibility via processing params
 *
 * FAIL FAST: All errors throw immediately with detailed error info
 * NO MOCKS: Tests use real DatabaseService
 */
import { DatabaseService } from '../storage/database/index.js';
import { ProvenanceTracker } from './tracker.js';
import { ProvenanceRecord } from '../../models/provenance.js';
export type ExportScope = 'document' | 'database';
export type ExportFormat = 'json' | 'w3c-prov' | 'csv';
/**
 * W3C PROV-JSON Document structure
 * Reference: https://www.w3.org/submissions/prov-json/
 */
interface PROVDocument {
    prefix: Record<string, string>;
    entity: Record<string, Record<string, unknown>>;
    activity: Record<string, Record<string, unknown>>;
    agent: Record<string, Record<string, unknown>>;
    wasDerivedFrom: Record<string, Record<string, unknown>>;
    wasGeneratedBy: Record<string, Record<string, unknown>>;
    wasAttributedTo: Record<string, Record<string, unknown>>;
}
/** Result of JSON export */
interface JSONExportResult {
    format: 'json';
    scope: ExportScope;
    document_id?: string;
    exported_at: string;
    record_count: number;
    records: ProvenanceRecord[];
}
/** Result of W3C PROV-JSON export */
interface W3CPROVExportResult {
    format: 'w3c-prov';
    scope: ExportScope;
    document_id?: string;
    exported_at: string;
    entity_count: number;
    activity_count: number;
    agent_count: number;
    prov_document: PROVDocument;
}
/** Result of CSV export */
interface CSVExportResult {
    format: 'csv';
    scope: ExportScope;
    document_id?: string;
    exported_at: string;
    record_count: number;
    csv_content: string;
}
/** Result of file export */
interface FileExportResult {
    success: boolean;
    format: ExportFormat;
    output_path: string;
    bytes_written: number;
    record_count: number;
}
/** Error codes for exporter operations - extends ProvenanceErrorCode */
export declare const ExporterErrorCode: {
    readonly INVALID_SCOPE: "INVALID_EXPORT_SCOPE";
    readonly INVALID_FORMAT: "INVALID_EXPORT_FORMAT";
    readonly FILE_WRITE_ERROR: "FILE_WRITE_ERROR";
    readonly DOCUMENT_REQUIRED: "DOCUMENT_ID_REQUIRED_FOR_SCOPE";
    readonly NOT_FOUND: "PROVENANCE_NOT_FOUND";
    readonly CHAIN_BROKEN: "PROVENANCE_CHAIN_BROKEN";
    readonly ROOT_NOT_FOUND: "ROOT_DOCUMENT_NOT_FOUND";
    readonly INVALID_TYPE: "INVALID_PROVENANCE_TYPE";
    readonly INVALID_PARAMS: "INVALID_PROVENANCE_PARAMS";
};
type ExporterErrorCodeType = (typeof ExporterErrorCode)[keyof typeof ExporterErrorCode];
/**
 * ExporterError - Typed error for export operations
 * FAIL FAST: Always throw with detailed error information
 */
export declare class ExporterError extends Error {
    readonly code: ExporterErrorCodeType;
    readonly details?: Record<string, unknown> | undefined;
    constructor(message: string, code: ExporterErrorCodeType, details?: Record<string, unknown> | undefined);
}
/**
 * ProvenanceExporter - Export provenance records in multiple formats
 *
 * Supports:
 * - JSON: Internal JSON format with full ProvenanceRecord data
 * - W3C PROV-JSON: Standard W3C PROV-JSON format for interoperability
 * - CSV: Tabular format for spreadsheet/analysis tools
 *
 * Scopes:
 * - document: Export all records for a specific root document
 * - database: Export all records in the database
 */
export declare class ProvenanceExporter {
    private readonly tracker;
    private readonly rawDb;
    private static readonly PROV_PREFIX;
    private static readonly OCR_PREFIX;
    private static readonly OCRP_PREFIX;
    constructor(db: DatabaseService, tracker: ProvenanceTracker);
    /**
     * Export provenance records as internal JSON format
     *
     * @param scope - 'document' (requires documentId) or 'database'
     * @param documentId - Required when scope='document'
     * @returns JSONExportResult with full ProvenanceRecord array
     * @throws ExporterError if scope invalid or documentId missing when required
     */
    exportJSON(scope: ExportScope, documentId?: string): Promise<JSONExportResult>;
    /**
     * Export provenance records as W3C PROV-JSON format
     *
     * Reference: https://www.w3.org/submissions/prov-json/
     *
     * Mapping:
     * - ProvenanceRecord -> prov:Entity
     * - Processing operation -> prov:Activity (non-DOCUMENT types)
     * - Processor -> prov:Agent
     * - source_id relationship -> wasDerivedFrom
     * - Processing creates record -> wasGeneratedBy
     * - Processor attribution -> wasAttributedTo
     *
     * @param scope - 'document' (requires documentId) or 'database'
     * @param documentId - Required when scope='document'
     * @returns W3CPROVExportResult with PROV-JSON document
     * @throws ExporterError if scope invalid or documentId missing when required
     */
    exportW3CPROV(scope: ExportScope, documentId?: string): Promise<W3CPROVExportResult>;
    /**
     * Export provenance records as CSV format
     *
     * @param scope - 'document' (requires documentId) or 'database'
     * @param documentId - Required when scope='document'
     * @returns CSVExportResult with CSV content string
     * @throws ExporterError if scope invalid or documentId missing when required
     */
    exportCSV(scope: ExportScope, documentId?: string): Promise<CSVExportResult>;
    /**
     * Export provenance records to a file
     *
     * Creates parent directories if they don't exist.
     *
     * @param outputPath - Absolute path to output file
     * @param format - 'json', 'w3c-prov', or 'csv'
     * @param scope - 'document' (requires documentId) or 'database'
     * @param documentId - Required when scope='document'
     * @returns FileExportResult with bytes written and path
     * @throws ExporterError if format invalid, scope invalid, or write fails
     */
    exportToFile(outputPath: string, format: ExportFormat, scope: ExportScope, documentId?: string): Promise<FileExportResult>;
    /**
     * Validate scope and documentId
     * @throws ExporterError if invalid
     */
    private validateScope;
    /**
     * Get provenance records for the given scope
     * Note: validateScope() must be called before this to ensure documentId is present when needed
     */
    private getRecordsForScope;
    /**
     * Get all provenance records from database
     * Ordered by chain_depth ASC, created_at ASC
     */
    private getAllProvenance;
    /**
     * Transform provenance records to W3C PROV-JSON format
     *
     * Mapping rules:
     * - Each ProvenanceRecord becomes an entity: ocr:<type>-<id>
     * - Non-DOCUMENT types create an activity: ocr:activity-<id>
     * - Unique agents per processor name
     * - wasDerivedFrom links entities with source_id
     * - wasGeneratedBy links entities to their activities
     * - wasAttributedTo links all entities to their processor agents
     */
    private transformToPROVJSON;
    /**
     * Sanitize processor name for use as agent ID
     * Only allows alphanumeric and hyphens
     */
    private sanitizeAgentId;
    /**
     * Transform provenance records to CSV format
     */
    private transformToCSV;
    /**
     * Escape a value for CSV
     * - Wrap in quotes if contains comma, quote, or newline
     * - Escape quotes by doubling them
     */
    private escapeCSV;
}
export {};
//# sourceMappingURL=exporter.d.ts.map