from __future__ import annotations

from typing import Any, Protocol

from app.rda.domain.models import RdaArtifactType


class CaseEpicrisisContextProvider(Protocol):
    def get_case_context(self, username: str, case_key: str, *, regen: bool = False) -> dict[str, Any]: ...


class RdaArtifactRepository(Protocol):
    def ensure_indexes(self) -> None: ...

    def get_latest(
        self, username: str, case_key: str, artifact_type: RdaArtifactType
    ) -> dict[str, Any] | None: ...

    def save_version(
        self,
        *,
        username: str,
        case_key: str,
        artifact_type: RdaArtifactType,
        payload: dict[str, Any],
        completeness_status: str,
        missing_fields: list[str],
        section_trace: list[dict[str, Any]],
        source_context: dict[str, Any],
        source_context_fingerprint: str,
        schema_version: int,
        mapper_version: str,
        regen_requested: bool,
    ) -> dict[str, Any]: ...


class RdaJobStatusRepository(Protocol):
    def ensure_indexes(self) -> None: ...

    def get_status(
        self, username: str, case_key: str, artifact_type: RdaArtifactType
    ) -> dict[str, Any] | None: ...

    def upsert_status(
        self,
        *,
        username: str,
        case_key: str,
        artifact_type: RdaArtifactType,
        status: str,
        job_id: str,
        error: str | None = None,
        source_context_fingerprint: str | None = None,
        resolved_version: int | None = None,
        reused: bool = False,
    ) -> dict[str, Any]: ...
