import { WorkspaceScopedResource, extractData } from './base.js';
/**
 * World Model — entities, events, relationships, and the entity timeline.
 *
 * The world model is the core knowledge graph of the platform. Entities
 * represent real-world objects (patients, contacts, calls). Events record
 * observations about entities over time.
 */
export class WorldResource extends WorkspaceScopedResource {
    // ---- Entities ----
    /** List entities with optional filtering */
    async listEntities(params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities', {
            params: { path: { workspace_id: this.workspaceId }, query: params },
        }));
    }
    listEntitiesAutoPaging(params) {
        return this.iterateOffsetPaginatedList((pageParams) => this.listEntities(pageParams), (page) => page.entities, params);
    }
    /** Get a single entity */
    async getEntity(entityId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}', {
            params: { path: { workspace_id: this.workspaceId, entity_id: entityId } },
        }));
    }
    /** Get all relationships for an entity */
    async getRelationships(entityId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}/relationships', {
            params: { path: { workspace_id: this.workspaceId, entity_id: entityId } },
        }));
    }
    /** Get the knowledge graph centered on an entity (entity + neighbors + edges) */
    async getGraph(entityId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}/graph', {
            params: { path: { workspace_id: this.workspaceId, entity_id: entityId } },
        }));
    }
    /** Get provenance — which source systems contributed data for an entity */
    async getProvenance(entityId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}/provenance', {
            params: { path: { workspace_id: this.workspaceId, entity_id: entityId } },
        }));
    }
    /** Get lineage — merge history and canonical identity for an entity */
    async getLineage(entityId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}/lineage', {
            params: { path: { workspace_id: this.workspaceId, entity_id: entityId } },
        }));
    }
    /** Get merged entities for a canonical entity */
    async getMerged(entityId) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}/merged', {
            params: { path: { workspace_id: this.workspaceId, entity_id: entityId } },
        }));
    }
    // ---- Connectors ----
    /** Get connected data sources overview with entity counts and sync status */
    async getConnectors() {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/connectors', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
    /** List entities from a specific connector / data source */
    async getConnectorEntities(dataSourceId, params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/connectors/{data_source_id}/entities', {
            params: {
                path: { workspace_id: this.workspaceId, data_source_id: dataSourceId },
                query: params,
            },
        }));
    }
    /** Search FHIR resources from a specific data source */
    async getConnectorResources(dataSourceId, params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/connectors/{data_source_id}/resources', {
            params: {
                path: { workspace_id: this.workspaceId, data_source_id: dataSourceId },
                query: params,
            },
        }));
    }
    // ---- Entity Types ----
    /** List registered entity types with counts and schemas */
    async listEntityTypes() {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entity-types', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
    // ---- Duplicate Detection ----
    /** List potential duplicate entity pairs for review or merging */
    async listDuplicates(params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/duplicates', {
            params: { path: { workspace_id: this.workspaceId }, query: params },
        }));
    }
    // ---- Semantic Search ----
    /** Semantic (vector) search over entities */
    async search(params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/search', {
            params: { path: { workspace_id: this.workspaceId }, query: params },
        }));
    }
    // ---- Timeline ----
    /** Get the event timeline for an entity (reverse-chronological) */
    async getTimeline(entityId, params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entities/{entity_id}/timeline', {
            params: {
                path: { workspace_id: this.workspaceId, entity_id: entityId },
                query: params,
            },
        }));
    }
    getTimelineAutoPaging(entityId, params) {
        return this.iterateOffsetPaginatedList((pageParams) => this.getTimeline(entityId, pageParams), (page) => page.events, params);
    }
    // ---- Sync ----
    /** Get sync status grouped by sink (Lakebase, Delta, etc.) */
    async getSyncStatusBySink() {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/sync/by-sink', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
    /** List sync events with status filtering */
    async listSyncEvents(params) {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/sync/events', {
            params: { path: { workspace_id: this.workspaceId }, query: params },
        }));
    }
    listSyncEventsAutoPaging(params) {
        return this.iterateOffsetPaginatedList((pageParams) => this.listSyncEvents(pageParams), (page) => page.events, params);
    }
    /** Get current sync queue depth */
    async getSyncQueueDepth() {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/sync/queue', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
    /** Retry a single failed sync event */
    async retrySyncEvent(eventId) {
        return extractData(await this.client.POST('/v1/{workspace_id}/world/sync/retry/{event_id}', {
            params: { path: { workspace_id: this.workspaceId, event_id: eventId } },
        }));
    }
    /** Retry all failed sync events */
    async retryAllSyncEvents() {
        return extractData(await this.client.POST('/v1/{workspace_id}/world/sync/retry-all', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
    // ---- Statistics ----
    /** Get aggregate entity and event statistics */
    async getStats() {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/entity-stats', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
    /** Get entity counts broken down by source system */
    async getSourceBreakdown() {
        return extractData(await this.client.GET('/v1/{workspace_id}/world/source-breakdown', {
            params: { path: { workspace_id: this.workspaceId } },
        }));
    }
}
//# sourceMappingURL=world.js.map