"""Puertos del módulo batch para desacoplar casos de uso e infraestructura."""

from __future__ import annotations

from typing import Protocol

from app.batch_processing.domain.models import (
    ArchiveExtractionResult,
    AssociationResult,
    ExtractedSignals,
)


class BatchRepository(Protocol):
    def create_batch(self, payload: dict) -> str: ...

    def update_batch(self, batch_id: str, payload: dict) -> None: ...

    def get_batch(self, batch_id: str) -> dict | None: ...

    def list_user_batches(self, username: str, *, limit: int = 20) -> list[dict]: ...


class BatchFileRepository(Protocol):
    def create_file(self, payload: dict) -> str: ...

    def update_file(self, file_id: str, payload: dict) -> None: ...

    def get_file(self, file_id: str) -> dict | None: ...

    def list_files(self, batch_id: str, *, status: str | None = None) -> list[dict]: ...


class BatchCaseRepository(Protocol):
    def replace_cases(self, batch_id: str, cases: list[dict]) -> None: ...

    def list_cases(self, batch_id: str) -> list[dict]: ...

    def get_case(self, batch_id: str, case_key: str) -> dict | None: ...

    def get_user_case(self, username: str, case_key: str) -> dict | None: ...

    def update_case(self, batch_id: str, case_key: str, payload: dict) -> None: ...


class BatchArchiveStore(Protocol):
    def save_archive(self, batch_id: str, filename: str, data: bytes) -> str: ...


class ArchiveExtractor(Protocol):
    def extract_archive(self, archive_path: str, batch_id: str) -> ArchiveExtractionResult: ...


class BatchArtifactCleaner(Protocol):
    def delete_archive(self, archive_path: str) -> None: ...

    def delete_extracted_file(self, file_path: str) -> None: ...


class BatchReportStore(Protocol):
    def save_excel_report(self, batch_id: str, filename: str, data: bytes) -> str: ...


class TextExtractor(Protocol):
    def extract_text(self, file_path: str) -> str: ...


class DocumentClassifier(Protocol):
    def classify(self, filename: str, text: str) -> str: ...


class CaseAssociationService(Protocol):
    def extract_signals(self, filename: str, text: str, detected_type: str) -> ExtractedSignals: ...

    def associate(self, file_records: list[dict]) -> AssociationResult: ...


class BatchJobDispatcher(Protocol):
    def dispatch(self, batch_id: str) -> None: ...
