/**
 * Hierarchical data model v2 for FB Form instances.
 *
 * Single source of truth for all form data across instances. The structure is
 * flattened compared to v1 — validations and clarifications are direct arrays
 * on each entry rather than nested inside activities[].
 *
 *   data[]
 *   ├── question (tagged with form_instance)
 *   ├── client_data[]
 *   │   └── client_input → processed_data[] (LLM-split items)
 *   ├── validations[] (flat, each with processed_data_ref)
 *   └── clarifications[] (flat, each with thread[], review, response_data[])
 *
 * Key design principles:
 * - Instance-independent: one data[] spans all form instances
 * - Thread captures full conversation history across instances
 * - Review decisions are direct properties, not buried in activities
 * - Clarifications reference processed_data via IDs, not nesting
 * - response_data links to thread entries via thread_ref + thread_index
 *
 * ID notation:
 *   ie_N         — input element (sequential)
 *   pd_N.M       — processed data (ie prefix + sequential suffix)
 *   val_N        — validation (sequential within entry)
 *   clr_*        — clarification (real IDs, not synthetic)
 *   th_N         — thread entry (sequential within clarification)
 */
/** The root data structure holding all form data entries across instances */
export interface FbFormData {
    data: FbDataEntry[];
}
/**
 * A single entry in the data[] array.
 * Represents a question posed to the client with all associated data:
 * inputs, processed data, validations, and clarifications.
 */
export interface FbDataEntry {
    /** Question metadata — what was asked of the client */
    question?: FbQuestion;
    /** Client inputs for this question */
    client_data?: FbClientDataItem[];
    /** All validations across all processed_data in this entry (flat, with processed_data_ref) */
    validations?: FbEntryValidation[];
    /** All clarifications raised for this entry (flat, each with thread and review state) */
    clarifications?: FbEntryClarification[];
    /** Autofill runs for files in this entry — tracks which files have been processed and their results */
    autofill_runs?: FbAutofillRun[];
}
/** Record of an autofill execution for a specific file+group combination */
export interface FbAutofillRun {
    /** hazo_files file ID that was processed */
    file_id: string;
    /** Display filename */
    file_name: string;
    /** Back-office group ID that received the extracted data */
    group_id: string;
    /** Outcome of the extraction */
    status: 'success' | 'error' | 'empty';
    /** Number of fields populated (0 for error/empty) */
    fields_populated: number;
    /** ISO 8601 timestamp of the run */
    time: string;
    /** Form instance number when the run occurred */
    form_instance: number;
    /** Error message (when status is 'error') */
    error?: string;
}
/** A question posed to the client — either a data request or a clarification */
export interface FbQuestion {
    /** Activity/source that spawned this question (null for root questions from form config) */
    source_id: string | null;
    /** Unique field ID for this question (e.g. 'q1_income') */
    question_field_id: string;
    /** Type of question */
    question_type: 'data_request' | 'clarification';
    /** Which form round/instance this question was first asked in (1, 2, 3, ...) */
    form_instance: number;
    /** UI component to render (e.g. 'HazoCollabFormFileTextbox', 'HazoCollabFormRFIbox') */
    component_type: string;
    /** Human-readable question text shown to the client */
    description: string;
}
/** A single client input element */
export interface FbClientDataItem {
    /** Unique input element ID (ie_N notation) */
    input_elt_id: string;
    /** The actual client input — single object or array for multi-block inputs */
    client_input: FbClientInput | FbClientInput[];
}
/** Status of a client input element */
export type FbInputStatus = 'draft' | 'complete';
/** Client-provided input data */
export interface FbClientInput {
    /** Type of input provided */
    data_type?: 'text' | 'file' | 'option';
    /** Free-text content */
    data_text?: string;
    /** Selected option code (from rfi_response_options) */
    data_option?: string;
    /** Attached file(s) */
    data_files?: FbFileRef | FbFileRef[] | null;
    /** Input status — 'draft' while editing, 'complete' after explicit submit */
    input_status?: FbInputStatus;
    /** LLM-processed data derived from this input */
    processed_data?: FbProcessedData[];
}
/** A single item produced by LLM processing (text splitting or file classification) */
export interface FbProcessedData {
    /** Unique ID (pd_N.M notation — prefix from input_elt_id, suffix sequential) */
    processed_data_id: string;
    /** Type of processed content */
    processed_data_type: 'text' | 'file' | 'structured' | null;
    /** Extracted/split text content */
    processed_data_text?: string;
    /** File reference for file-type processed data */
    processed_data_files?: FbFileRef;
    /** Classification tags assigned by LLM */
    tags?: string[] | null;
    /** Category classification (e.g. 'bank_interest', 'salary') */
    processed_data_category?: string[] | null;
    /** Nature/document type (e.g. 'Bank Statement', 'Payslip') */
    processed_data_nature?: string[] | null;
}
/** A validation result attached to a specific processed_data item */
export interface FbEntryValidation {
    /** Unique validation ID */
    validation_id: string;
    /** Which processed_data item this validation applies to (null for group-level missing-file issues) */
    processed_data_ref: string | null;
    /** What rule was checked (e.g. 'date_check', 'name_check', 'support_check') */
    rule_key: string;
    /** What triggered this validation */
    trigger: 'client_facing' | 'back_office';
    /** Result */
    status: FbValidationStatus;
    /** Human-readable description of what was validated */
    details: string;
}
/** Status of a validation check */
export type FbValidationStatus = 'passed' | 'failed';
/** Lifecycle status of a clarification */
export type FbClarificationStatus = 'pending' | 'responded' | 'accepted' | 'sent_back' | 'resolved';
/** A clarification raised for a processed_data item, with full conversation history */
export interface FbEntryClarification {
    /** Unique clarification ID (real ID, not synthetic) */
    clarification_id: string;
    /** Which processed_data item this clarification relates to */
    processed_data_ref: string;
    /** Which validation triggered this clarification (null if manually created) */
    validation_ref: string | null;
    /** The issue description shown to the client (group summary when child_issues is set) */
    issue: string;
    /** Current lifecycle status */
    status: FbClarificationStatus;
    /** Available response options for the client */
    response_options: FbRfiResponseOption[];
    /** Chronological conversation thread spanning all form instances */
    thread: FbThreadEntry[];
    /** Latest agent review snapshot (null when awaiting review) */
    review: FbClarificationReview | null;
    /** Processed data from client responses (files, text) linked to thread entries */
    response_data: FbResponseData[];
    /** Structured expectation derived from the originating validation issue. */
    expectation?: import('./clarification.js').ClarificationExpectation;
    /**
     * When this clarification represents a bulk group (one rule firing produced many
     * issues that were sent back as one), child_issues lists the underlying issues.
     * Absent for single-issue clarifications.
     */
    child_issues?: FbChildIssue[];
}
/**
 * Underlying issue covered by a grouped FbEntryClarification.
 * Carries the fields needed to re-render the issue list in the spawned send-back
 * task without re-running validation.
 */
export interface FbChildIssue {
    /** Original ValidationIssue.issue_id — stable across re-runs */
    issue_id: string;
    issue_description: string;
    /** ISO date for time-bucket rendering */
    date?: string;
    /** Category for category-bucket rendering */
    kind?: 'file_issue' | 'missing_file';
    /** Monetary amount referenced */
    amount?: string;
}
/** Role of a thread participant */
export type FbThreadRole = 'system' | 'client' | 'agent';
/** Action taken in a thread entry */
export type FbThreadAction = 'issue_found' | 'responded' | 'reviewed';
/** A single entry in a clarification's conversation thread */
export interface FbThreadEntry {
    /** Unique thread entry ID within this clarification (th_1, th_2, ...) */
    thread_id: string;
    /** Which form instance this entry was created in */
    form_instance: number;
    /** Who created this entry */
    role: FbThreadRole;
    /** What action was taken */
    action: FbThreadAction;
    /** ISO 8601 timestamp */
    time: string;
    /** Issue description (when action='issue_found') */
    message?: string;
    /** Selected response option code */
    choice?: string;
    /** Client's free-text comment */
    comment?: string;
    /** Files attached by the client */
    files?: FbFileRef[];
    /** Agent's review decision */
    decision?: 'accept' | 'send_back';
    /** Agent's feedback/comment to client */
    feedback?: string;
    /** Agent user identifier */
    user?: string;
    /** Agent user display name */
    user_name?: string;
    /** Aggregate-level check result for this response (sum_match, etc.). */
    resolution_check?: ResolutionCheck;
}
/**
 * Aggregate validation outcome for a clarification response, computed at send time.
 * Stored on the FbThreadEntry that recorded the response so each round has its own check.
 */
export interface ResolutionCheck {
    /** Whether the deterministic check passed (math + date range). */
    passed: boolean;
    /** sum_actual − sum_expected (negative means short, positive means over). */
    delta: number;
    /** Sum of extracted totals across response files. */
    sum_actual: number;
    /** Expected total from the clarification's expectation. */
    sum_expected: number;
    /** Per-file LLM commentary keyed by file_id. May be empty if commentary failed. */
    file_notes: Record<string, string>;
    /** Per-file LLM relevance verdict keyed by file_id. */
    file_relevance?: Record<string, ResolutionRelevance>;
    /** Plain-English summary of the verdict (kept for back-compat / fallback rendering). */
    summary: string;
    /** Structured detail items for bullet rendering — preferred over `summary` when present. */
    details?: ResolutionDetail[];
    /** ISO 8601 timestamp the check ran. */
    ran_at: string;
}
/** Per-file relevance verdict carried inside a ResolutionCheck. */
export interface ResolutionRelevance {
    verdict: 'matches' | 'mismatch' | 'unclear' | 'off_topic';
    reason: string;
}
/** A single bullet shown in the Resolution Status panel. */
export interface ResolutionDetail {
    /** Category — drives icon/colour in the renderer. */
    kind: 'sum' | 'off_topic' | 'mismatch' | 'unclear' | 'date_violation' | 'missing_total' | 'success';
    /** Visual severity. 'success' = green tick, 'warning' = amber, 'info' = neutral. */
    severity: 'success' | 'warning' | 'info';
    /** Bullet text (client-facing). */
    message: string;
    /** File this bullet relates to (when applicable). */
    file_id?: string;
    file_name?: string;
}
/** Latest agent review decision for a clarification */
export interface FbClarificationReview {
    /** The decision */
    decision: 'accept' | 'send_back';
    /** Which thread entry this review responds to (the client response being reviewed) */
    thread_ref: string;
    /** Agent's feedback message to the client */
    feedback?: string;
    /** Agent user identifier */
    user?: string;
    /** Agent user display name */
    user_name?: string;
    /** ISO 8601 timestamp of the review */
    time?: string;
}
/** Processed data produced from a client's response to a clarification */
export interface FbResponseData {
    /** Links to the thread entry that triggered this response */
    thread_ref: string;
    /** Index of the thread entry (for readability) */
    thread_index: number;
    /** Which form instance the response was submitted in */
    form_instance: number;
    /** Processed data items from the response (files uploaded, text provided) */
    processed_data: FbResponseProcessedData[];
}
/** A processed data item from a client response, with inline validations */
export interface FbResponseProcessedData {
    /** Unique processed data ID */
    processed_data_id: string;
    /** Type of processed content */
    processed_data_type: 'text' | 'file' | null;
    /** Text content */
    processed_data_text?: string;
    /** File reference */
    processed_data_files?: FbFileRef;
    /** Classification tags */
    tags?: string[] | null;
    /** Category classification */
    processed_data_category?: string[] | null;
    /** Nature/document type */
    processed_data_nature?: string[] | null;
    /** Validations run on this response data (inline, not entry-level) */
    validations?: FbEntryValidation[];
    /** Structured fields pulled by autofill extraction (used by sum_match resolver). */
    extracted_fields?: ExtractedResponseFields;
}
/**
 * Structured fields extracted from a response file by the classification LLM.
 *
 * Growing set: new evidence fields land here without touching consumers. The
 * classification prompt and the resolver agree on this shape, so adding a
 * field is two edits — the prompt's example output and this interface.
 */
export interface ExtractedResponseFields {
    /** Total monetary amount in major units (e.g. 234.50). */
    total?: number;
    /** ISO date (YYYY-MM-DD) of the document. */
    date?: string;
    /** Vendor / supplier name. */
    vendor?: string;
    /**
     * Property address mentioned in the document, when applicable. Used by the
     * relevance check to verify a receipt belongs to the property the
     * clarification was raised about. Free-form — fuzzy-matched against the
     * expectation by the LLM commentary step.
     */
    property_address?: string;
    /** Original raw extraction payload, for debugging or future fields. */
    raw?: Record<string, unknown>;
}
/** A response option presented to the client in a clarification */
export interface FbRfiResponseOption {
    /** Machine-readable option code */
    code: string;
    /** Human-readable option text */
    label: string;
    /** Whether this option allows file uploads */
    accept_files?: boolean;
    /** Whether this option allows a text comment */
    accept_comment?: boolean;
    /** Whether the comment is mandatory when this option is selected */
    accept_comment_mandatory?: boolean;
}
/** Result of an autofill extraction for a single file+group */
export interface FbAutofillResult {
    /** hazo_files file ID that was processed */
    file_id: string;
    /** Display filename */
    file_name: string;
    /** Back-office group ID that received the extracted data */
    group_id: string;
    /** Prompt area used for extraction */
    prompt_area: string;
    /** Prompt key used for extraction */
    prompt_key: string;
    /** Number of fields that were populated */
    fields_populated: number;
    /** Per-field extraction details */
    details: FbAutofillFieldDetail[];
    /** Time taken for the autofill API call in milliseconds */
    duration_ms: number;
    /** Outcome of the extraction */
    status: 'success' | 'error' | 'empty';
    /** Error message (when status is 'error') */
    error?: string;
}
/** Detail of a single field populated by autofill */
export interface FbAutofillFieldDetail {
    /** Field ID that was populated */
    field_id: string;
    /** Human-readable field label */
    field_label: string;
    /** Summary of the extracted value */
    value_summary: string;
}
/** Reference to a file in hazo_files */
export interface FbFileRef {
    /** hazo_files file ID */
    file_id: string;
    /** Display filename */
    file_name: string;
    /** Human-readable file size (e.g. '24k', '44kb') */
    file_size?: string;
}
/** Generate the next input element ID (ie_N) */
export declare function next_ie_id(data: FbDataEntry[]): string;
/** Generate the next processed data ID (pd_N.M) for a given input element number */
export declare function next_pd_id(ie_num: number, existing_pds: FbProcessedData[]): string;
/** Generate the next validation ID (val_N) within an entry */
export declare function next_val_id(existing_validations: FbEntryValidation[]): string;
/** Generate the next thread ID (th_N) within a clarification */
export declare function next_thread_id(existing_thread: FbThreadEntry[]): string;
//# sourceMappingURL=shared_data.d.ts.map