/**
 * Stoneforge API Implementation
 *
 * This module provides the concrete implementation of the QuarryAPI interface,
 * connecting the type system to the storage layer with full CRUD operations.
 */
import type { StorageBackend } from '@stoneforge/storage';
import type { Element, ElementId, EntityId, ElementType, Timestamp, Task, Document, DocumentId, Dependency, DependencyType, Event, EventFilter, Channel, PlanProgress, Entity, CreateTaskInput, OrgChartNode } from '@stoneforge/core';
import type { QuarryAPI, ElementFilter, TaskFilter, ChannelFilter, GetOptions, BlockedTask, DependencyTree, DependencyInput, ListResult, ImportResult, ImportOptions, ExportOptions, SystemStats, UpdateOptions, DeleteOptions, AddTaskToPlanOptions, CreateTaskInPlanOptions, BulkCloseOptions, BulkDeferOptions, BulkReassignOptions, BulkTagOptions, BulkOperationResult, DeleteWorkflowOptions, DeleteWorkflowResult, GarbageCollectionOptions, GarbageCollectionResult, TaskGarbageCollectionOptions, TaskGarbageCollectionResult, TeamMembershipResult, TeamMetrics, OperationOptions, ReconstructedState, ElementTimeline, WorkflowProgress, FTSSearchOptions, FTSSearchResult } from './types.js';
import { type ApprovalResult, type AddMemberOptions, type RemoveMemberOptions, type MembershipResult, type FindOrCreateDirectChannelResult, type SendDirectMessageInput, type SendDirectMessageResult } from './types.js';
import type { EmbeddingService } from '../services/embeddings/service.js';
/**
 * Implementation of the QuarryAPI interface
 */
export declare class QuarryAPIImpl implements QuarryAPI {
    private backend;
    private blockedCache;
    private priorityService;
    private syncService;
    private inboxService;
    private embeddingService?;
    constructor(backend: StorageBackend);
    /**
     * Internal method to update task status without triggering additional blocked cache updates.
     * Used for automatic blocked/unblocked status transitions.
     */
    private updateTaskStatusInternal;
    get<T extends Element>(id: ElementId, options?: GetOptions): Promise<T | null>;
    list<T extends Element>(filter?: ElementFilter): Promise<T[]>;
    listPaginated<T extends Element>(filter?: ElementFilter): Promise<ListResult<T>>;
    create<T extends Element>(input: Record<string, unknown> & {
        type: ElementType;
        createdBy: EntityId;
    }): Promise<T>;
    update<T extends Element>(id: ElementId, updates: Partial<T>, options?: UpdateOptions): Promise<T>;
    delete(id: ElementId, options?: DeleteOptions): Promise<void>;
    lookupEntityByName(name: string): Promise<Element | null>;
    /**
     * Sets the manager (reportsTo) for an entity.
     *
     * Validates:
     * - Entity exists and is an entity type
     * - Manager entity exists and is active
     * - No self-reference (entity cannot report to itself)
     * - No circular chains
     *
     * @param entityId - The entity to set the manager for
     * @param managerId - The manager entity ID
     * @param actor - Entity performing this action (for audit trail)
     * @returns The updated entity
     */
    setEntityManager(entityId: EntityId, managerId: EntityId, actor: EntityId): Promise<Entity>;
    /**
     * Clears the manager (reportsTo) for an entity.
     *
     * @param entityId - The entity to clear the manager for
     * @param actor - Entity performing this action (for audit trail)
     * @returns The updated entity
     */
    clearEntityManager(entityId: EntityId, actor: EntityId): Promise<Entity>;
    /**
     * Gets all entities that report directly to a manager.
     *
     * @param managerId - The manager entity ID
     * @returns Array of entities that report to the manager
     */
    getDirectReports(managerId: EntityId): Promise<Entity[]>;
    /**
     * Gets the management chain for an entity (from entity up to root).
     *
     * Returns an ordered array starting with the entity's direct manager
     * and ending with the root entity (an entity with no reportsTo).
     *
     * @param entityId - The entity to get the management chain for
     * @returns Array of entities in the management chain (empty if no manager)
     */
    getManagementChain(entityId: EntityId): Promise<Entity[]>;
    /**
     * Gets the organizational chart structure.
     *
     * @param rootId - Optional root entity ID (if not provided, returns all root entities)
     * @returns Array of org chart nodes (hierarchical structure)
     */
    getOrgChart(rootId?: EntityId): Promise<OrgChartNode[]>;
    addTaskToPlan(taskId: ElementId, planId: ElementId, options?: AddTaskToPlanOptions): Promise<Dependency>;
    removeTaskFromPlan(taskId: ElementId, planId: ElementId, actor?: EntityId): Promise<void>;
    getTasksInPlan(planId: ElementId, filter?: TaskFilter): Promise<Task[]>;
    getPlanProgress(planId: ElementId): Promise<PlanProgress>;
    createTaskInPlan<T extends Task = Task>(planId: ElementId, taskInput: Omit<CreateTaskInput, 'id'>, options?: CreateTaskInPlanOptions): Promise<T>;
    bulkClosePlanTasks(planId: ElementId, options?: BulkCloseOptions): Promise<BulkOperationResult>;
    bulkDeferPlanTasks(planId: ElementId, options?: BulkDeferOptions): Promise<BulkOperationResult>;
    bulkReassignPlanTasks(planId: ElementId, newAssignee: EntityId | undefined, options?: BulkReassignOptions): Promise<BulkOperationResult>;
    bulkTagPlanTasks(planId: ElementId, options: BulkTagOptions): Promise<BulkOperationResult>;
    ready(filter?: TaskFilter): Promise<Task[]>;
    /**
     * Get tasks in backlog (not ready for work, needs triage)
     */
    backlog(filter?: TaskFilter): Promise<Task[]>;
    blocked(filter?: TaskFilter): Promise<BlockedTask[]>;
    addDependency(dep: DependencyInput): Promise<Dependency>;
    removeDependency(blockedId: ElementId, blockerId: ElementId, type: DependencyType, actor?: EntityId): Promise<void>;
    getDependencies(id: ElementId, types?: DependencyType[]): Promise<Dependency[]>;
    getDependents(id: ElementId, types?: DependencyType[]): Promise<Dependency[]>;
    getDependencyTree(id: ElementId): Promise<DependencyTree>;
    satisfyGate(blockedId: ElementId, blockerId: ElementId, actor: EntityId): Promise<boolean>;
    recordApproval(blockedId: ElementId, blockerId: ElementId, approver: EntityId): Promise<ApprovalResult>;
    removeApproval(blockedId: ElementId, blockerId: ElementId, approver: EntityId): Promise<ApprovalResult>;
    search(query: string, filter?: ElementFilter): Promise<Element[]>;
    searchChannels(query: string, filter?: ChannelFilter): Promise<Channel[]>;
    getEvents(id: ElementId, filter?: EventFilter): Promise<Event[]>;
    listEvents(filter?: EventFilter): Promise<Event[]>;
    countEvents(filter?: EventFilter): Promise<number>;
    getDocumentVersion(id: DocumentId, version: number): Promise<Document | null>;
    getDocumentHistory(id: DocumentId): Promise<Document[]>;
    reconstructAtTime<T extends Element = Element>(id: ElementId, asOf: Timestamp): Promise<ReconstructedState<T> | null>;
    getElementTimeline(id: ElementId, filter?: EventFilter): Promise<ElementTimeline>;
    findOrCreateDirectChannel(entityA: EntityId, entityB: EntityId, actor: EntityId): Promise<FindOrCreateDirectChannelResult>;
    addChannelMember(channelId: ElementId, entityId: EntityId, options?: AddMemberOptions): Promise<MembershipResult>;
    removeChannelMember(channelId: ElementId, entityId: EntityId, options?: RemoveMemberOptions): Promise<MembershipResult>;
    leaveChannel(channelId: ElementId, actor: EntityId): Promise<MembershipResult>;
    /**
     * Merge two group channels: move all messages from source to target,
     * merge member lists, and archive the source channel.
     *
     * Only group channels can be merged. Direct channels are rejected.
     */
    mergeChannels(sourceId: ElementId, targetId: ElementId, options?: {
        newName?: string;
        actor?: EntityId;
    }): Promise<{
        target: Channel;
        sourceArchived: boolean;
        messagesMoved: number;
    }>;
    /**
     * Send a direct message to another entity
     *
     * This is a convenience method that:
     * 1. Finds or creates the direct channel between sender and recipient
     * 2. Creates and sends the message in that channel
     *
     * @param sender - The entity sending the message
     * @param input - The message input including recipient, contentRef, etc.
     * @returns The created message and channel information
     */
    sendDirectMessage(sender: EntityId, input: SendDirectMessageInput): Promise<SendDirectMessageResult>;
    deleteWorkflow(workflowId: ElementId, options?: DeleteWorkflowOptions): Promise<DeleteWorkflowResult>;
    garbageCollectWorkflows(options: GarbageCollectionOptions): Promise<GarbageCollectionResult>;
    garbageCollectTasks(_options: TaskGarbageCollectionOptions): Promise<TaskGarbageCollectionResult>;
    getTasksInWorkflow(workflowId: ElementId, filter?: TaskFilter): Promise<Task[]>;
    getReadyTasksInWorkflow(workflowId: ElementId, filter?: TaskFilter): Promise<Task[]>;
    getWorkflowProgress(workflowId: ElementId): Promise<WorkflowProgress>;
    /**
     * Get tasks in a workflow ordered by execution order (topological sort).
     *
     * Tasks are ordered such that blockers come before the tasks they block.
     * This represents the order in which tasks should be executed.
     *
     * @param workflowId - The workflow ID
     * @param filter - Optional filter to apply to tasks
     * @returns Tasks in execution order (topological sort based on blocks dependencies)
     */
    getOrderedTasksInWorkflow(workflowId: ElementId, filter?: TaskFilter): Promise<Task[]>;
    /**
     * Get all dependencies from storage
     */
    private getAllDependencies;
    archiveDocument(id: ElementId): Promise<Document>;
    unarchiveDocument(id: ElementId): Promise<Document>;
    registerEmbeddingService(service: EmbeddingService): void;
    private checkFTSAvailable;
    /**
     * Index a document in the FTS5 virtual table for full-text search.
     * Called after document creation and update.
     */
    private indexDocumentForFTS;
    /**
     * Reindex all documents in the FTS5 virtual table.
     * Does NOT create version history entries — safe for bulk reindex.
     */
    reindexAllDocumentsFTS(): {
        indexed: number;
        errors: number;
    };
    /**
     * Reindex imported documents after sync completes.
     * Called internally after import operations.
     */
    private reindexDocumentsAfterImport;
    searchDocumentsFTS(query: string, options?: FTSSearchOptions): Promise<FTSSearchResult[]>;
    export(options?: ExportOptions): Promise<string | void>;
    import(options: ImportOptions): Promise<ImportResult>;
    /**
     * Convert SyncService ImportResult to API ImportResult format
     */
    private convertSyncImportResult;
    addTeamMember(teamId: ElementId, entityId: EntityId, options?: {
        actor?: EntityId;
    }): Promise<TeamMembershipResult>;
    removeTeamMember(teamId: ElementId, entityId: EntityId, options?: {
        actor?: EntityId;
        reason?: string;
    }): Promise<TeamMembershipResult>;
    getTasksForTeam(teamId: ElementId, options?: TaskFilter): Promise<Task[]>;
    claimTaskFromTeam(taskId: ElementId, entityId: EntityId, options?: OperationOptions): Promise<Task>;
    getTeamMetrics(teamId: ElementId): Promise<TeamMetrics>;
    stats(): Promise<SystemStats>;
    /**
     * Batch fetch tags for multiple elements by their IDs.
     * Returns a map of element ID to array of tags for efficient lookup.
     * This eliminates N+1 query issues when fetching tags for multiple elements.
     */
    private batchFetchTags;
    private hydrateTask;
    /**
     * Batch fetch documents by their IDs.
     * Returns a map of document ID to document for efficient lookup.
     */
    private batchFetchDocuments;
    /**
     * Batch hydrate tasks with their document references.
     * Collects all document IDs, fetches them in a single query, then populates.
     */
    private hydrateTasks;
    /**
     * Hydrate a single message with its document references.
     * Resolves contentRef -> content and attachments -> attachmentContents.
     */
    private hydrateMessage;
    /**
     * Batch hydrate messages with their document references.
     * Collects all document IDs, fetches them in a single query, then populates.
     */
    private hydrateMessages;
    /**
     * Hydrate a single library with its document references.
     * Resolves descriptionRef -> description.
     */
    private hydrateLibrary;
    /**
     * Batch hydrate libraries with their document references.
     * Collects all document IDs, fetches them in a single query, then populates.
     */
    private hydrateLibraries;
    /**
     * Rebuild the blocked cache from scratch.
     *
     * Use this for:
     * - Initial population after migration
     * - Recovery from cache corruption
     * - Periodic consistency checks
     *
     * @returns Statistics about the rebuild
     */
    rebuildBlockedCache(): {
        elementsChecked: number;
        elementsBlocked: number;
        durationMs: number;
    };
}
/**
 * Create a new QuarryAPI instance
 *
 * @param backend - The storage backend to use
 * @returns A new QuarryAPI instance
 */
export declare function createQuarryAPI(backend: StorageBackend): QuarryAPI;
//# sourceMappingURL=quarry-api.d.ts.map