"""TypedDict definitions for TrustMem SDK return types.

These are used for type annotations only (TYPE_CHECKING) and do not
affect runtime behavior.
"""
from __future__ import annotations

from typing import Any, TypedDict


class ExtractedFact(TypedDict, total=False):
    memory_id: str | None
    content: str
    event: str
    confidence: str | None
    conflict_with: str | None
    reason: str
    winner: str


class AddStats(TypedDict, total=False):
    total_extracted: int
    added: int
    skipped: int
    contradicted: int
    entities_added: int
    entities_updated: int
    relations_added: int


class AddResult(TypedDict, total=False):
    extracted: list[ExtractedFact]
    entities: list[dict[str, Any]]
    relations: list[dict[str, Any]]
    stats: AddStats
    conversation_id: str | None
    extraction_failed: bool


class MemoryRecord(TypedDict, total=False):
    memory_id: str
    content: str
    confidence: str
    user_id: str
    created_at: str
    updated_at: str
    last_evaluated_at: str | None
    freshness: int | None
    tags: list[str]
    metadata: dict[str, Any]


class RelationRecord(TypedDict, total=False):
    edge_id: str
    subject_name: str
    subject_type: str
    predicate: str
    object_name: str
    object_type: str
    user_id: str


class SearchResult(TypedDict):
    results: list[MemoryRecord]
    relations: list[RelationRecord]


class GetAllResult(TypedDict):
    results: list[MemoryRecord]
    relations: list[RelationRecord]


class VerifyResult(TypedDict, total=False):
    memory_id: str
    valid: bool
    stored_hash: str
    computed_hash: str
    auto_quarantined: bool


class VerifyAllResult(TypedDict, total=False):
    total: int
    valid: int
    invalid: int
    invalid_results: list[VerifyResult]


class StatsResult(TypedDict, total=False):
    total_memories: int
    confidence_distribution: dict[str, int]


class EntityStatsResult(TypedDict, total=False):
    total_entities: int
    total_edges: int


class AddRawResult(TypedDict, total=False):
    memory_id: str
    content_hash: str
    confidence: str
    source_trust: str
    embedding_status: str
