"""Stub file for eval directory."""
from typing import Any, Callable

from .contracts import SplitEvaluatorProtocol
from .eval_model_loader import ModelLoaderCallable, load_model_with_runtime
from .eval_model_loader import load_model_with_runtime
from .evaluator import evaluate_available_splits
from .exceptions import InferenceRunnerError
from .exceptions import InferenceRunnerError, ModelLoadError
from .exceptions import PayloadFormatError
from .exceptions import RuntimeNotSupportedError
from .inference_runners import RunnerCallable, get_inference_runner
from .runtime_registry import RuntimeTaskRegistry
from .schemas import MetricPayload
from .schemas import MetricPayload, validate_payload
from .status_handler import EvaluationStatusReporter

# Constants
ModelLoaderCallable: Any = ...  # From eval_model_loader
RunnerCallable: Any = ...  # From inference_runners
MetricPayload: Any = ...  # From result_formatter
MetricPayload: Any = ...  # From schemas

# Functions
# From classification_runtime_adapters
def allocate_buffers(engine: Any) -> tuple[Any, Any, Any, Any, Any]:
    """
    Create host/device buffers for TensorRT engine I/O.
    """
    ...

# From classification_runtime_adapters
def do_inference(_engine: Any, context: Any, h_input: Any, d_input: Any, h_output: Any, d_output: Any, stream: Any) -> Any:
    """
    Run one TensorRT inference step and return output buffer.
    """
    ...

# From classification_runtime_adapters
def get_onnx_inference_results(loader: Any, model: Any, action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference on ONNX Runtime.
    """
    ...

# From classification_runtime_adapters
def get_openvino_inference_results(loader: Any, model: tuple[Any, Any], action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference on OpenVINO runtime.
    """
    ...

# From classification_runtime_adapters
def get_pytorch_inference_results(loader: Any, model: Any, action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference on PyTorch/TorchScript runtime.
    """
    ...

# From classification_runtime_adapters
def get_tensorrt_inference_results(loader: Any, model: tuple[Any, Any], action_tracker: Any) -> tuple[Any.Any, Any.Any, Any.Any]:
    """
    Run classification inference on TensorRT runtime.
    """
    ...

# From classification_runtime_adapters
def load_classification_model(action_tracker: Any, runtime_framework: str = 'pytorch') -> Any:
    """
    Load classification model artifact for requested runtime.
    """
    ...

# From classification_runtime_adapters
def load_engine(trt_filename: str) -> tuple[Any, Any]:
    """
    Deserialize TensorRT engine and build execution context.
    """
    ...

# From classification_runtime_adapters
def setup_tensorrt() -> tuple[Any, Any]:
    """
    Import TensorRT + PyCUDA lazily to keep base runtime lightweight.
    """
    ...

# From classification_runtime_adapters
def validate_device(loaded_model: Any.Any.Any) -> tuple[Any.Any.Any, Any.Any]:
    """
    Move model to best available device; fallback to CPU safely.
    """
    ...

# From common_classification
def build_imagefolder_loaders(data_root: str, batch_size: int, workers: int) -> tuple[Any.Any.Any.Any | None, Any.Any.Any.Any | None, Any.Any.Any.Any | None]:
    """
    Build train/val/test loaders for ImageFolder directory layout.
    """
    ...

# From compat
def ensure_metric_functions(metric_functions: Any[str, Any]) -> dict[str, Any]:
    """
    Ensure formatter-required keys exist with safe defaults.
    """
    ...

# From compat
def make_legacy_split_evaluator(legacy_get_metrics: Callable[..., Any], **extra_kwargs: Any) -> Callable[[str, Any], Any]:
    """
    Wrap legacy get_metrics function into a split callback signature.
    
        The returned callable matches: ``fn(split, loader) -> payload``.
    """
    ...

# From dataset_utils
def build_split_loader_map(requested_splits: Any[str], train_loader: Any | None, val_loader: Any | None, test_loader: Any | None) -> dict[str, Any]:
    """
    Create split->loader map while skipping missing loaders.
    """
    ...

# From eval_model_loader
def load_model_with_runtime(action_tracker: Any, runtime_framework: str, loaders: dict[str, Any], default_key: str = 'pytorch') -> Any:
    """
    Load evaluation model by runtime, with framework alias fallback.
    """
    ...

# From evaluator
def evaluate_available_splits(requested_splits: Any[str], split_to_loader: Any[str, Any], evaluate_split: Callable[[str, Any], list[dict]]) -> list[dict]:
    """
    Run split evaluator for available loaders and concatenate payload.
    """
    ...

# From inference_outputs
def coerce_classification_output(raw: Any) -> Any:
    """
    Convert tuple/object output to ClassificationInferenceOutput.
    """
    ...

# From inference_outputs
def coerce_detection_output(raw: Any) -> Any:
    """
    Convert tuple/object output to DetectionInferenceOutput.
    """
    ...

# From inference_runners
def get_inference_runner(runtime_framework: str, runners: dict[str, Any], default_key: str = 'pytorch') -> Any:
    """
    Resolve a runtime framework to a registered inference callable.
    """
    ...

# From orchestrator
def build_runtime_split_evaluator(registry: Any) -> Callable[[str, Any], Any]:
    """
    Create split evaluator using runtime registry.
    
        ``split_formatter`` receives ``(split, raw_runner_output)`` and must return
        normalized payload records for that split.
    """
    ...

# From orchestrator
def load_model_from_registry(registry: Any) -> Any:
    """
    Load model using task/runtime registry and raise typed errors.
    """
    ...

# From result_formatter
def format_classification_results(split: str, predictions: Any, output: Any, target: Any, index_to_labels: Any[str, str], metric_functions: Any[str, Any]) -> Any:
    """
    Build standardized single-label classification metric payload.
    """
    ...

# From result_formatter
def format_detection_results(split: str, precision: Any[Any], recall: Any[Any], f1_score: Any[Any], index_to_labels: Any[str, str], mAP50: Any | None = None, mAP50_95: Any | None = None) -> Any:
    """
    Build standardized detection payload from per-class vectors.
    """
    ...

# From result_formatter
def format_keypoint_results(split: str, keypoint_names: Any[str] | None = None, mAP: Any | None = None, mAP50: Any | None = None, oks_mAP: Any | None = None, pck: Any | None = None, per_keypoint_pck: Any[Any] | None = None) -> Any:
    """
    Build keypoint/pose estimation payload.
    """
    ...

# From result_formatter
def format_multilabel_results(split: str, per_class_precision: Any[Any], per_class_recall: Any[Any], per_class_f1: Any[Any], macro_f1: Any | None, micro_f1: Any | None, mAP: Any | None, index_to_labels: Any[str, str]) -> Any:
    """
    Build multi-label classification payload.
    """
    ...

# From result_formatter
def format_ocr_results(split: str, cer: Any | None = None, wer: Any | None = None, precision: Any | None = None, recall: Any | None = None, f1_score: Any | None = None) -> Any:
    """
    Build OCR/text pipeline payload.
    """
    ...

# From result_formatter
def format_tracking_results(split: str, mota: Any | None = None, motp: Any | None = None, idf1: Any | None = None, hota: Any | None = None, fp: Any | None = None, fn: Any | None = None, ids: Any | None = None) -> Any:
    """
    Build MOT-style tracking payload.
    """
    ...

# From result_formatter
def format_yolo_results(yolo_result: Any, split: str) -> Any:
    """
    Build detection payload from Ultralytics YOLO validation result object.
    """
    ...

# From schemas
def validate_metric_record(item: dict[str, Any], index: int = 0) -> Any:
    """
    Validate and normalize a metric record with Pydantic.
    """
    ...

# From schemas
def validate_payload(payload: Any[dict[str, Any]]) -> Any:
    """
    Validate and normalize a full metric payload list with Pydantic.
    """
    ...

# From status_handler
def safe_update_status(action_tracker: Any, step_code: str, status: str, description: str) -> None:
    """
    Best-effort status update that never raises to caller.
    """
    ...

# Classes
# From contracts
class ActionTrackerProtocol:
    # Minimal tracker interface used by eval flows.

    def log_error(self: Any, file_path: str, module: str, message: str) -> Any:
        """
        Persist an evaluation error entry for observability.
        """
        ...

    def save_evaluation_results(self: Any, payload: Any) -> Any:
        """
        Persist normalized evaluation payload records.
        """
        ...

    def update_status(self: Any, step_code: str, status: str, description: str) -> None:
        """
        Persist lifecycle status for a specific evaluation step.
        """
        ...


# From contracts
class InferenceRunnerProtocol:
    # Inference runner callable contract.
    #
    #     Runners usually return tuples like:
    #     - (predictions, outputs, targets) for classification
    #     - (outputs, targets) for detection/segmentation

    ...

# From contracts
class ModelLoaderProtocol:
    # Runtime model loader callable contract.

    ...

# From contracts
class ResultFormatterProtocol:
    # Result formatter callable contract.

    ...

# From contracts
class SplitEvaluatorProtocol:
    # Single split evaluator callable contract.

    ...

# From eval_model_loader
class ModelLoaderRegistry:
    # Runtime-keyed model loader registry.

    def register(self: Any, runtime_key: str, loader: Any) -> None:
        """
        Register a model loader for a runtime key.
        """
        ...

    def resolve(self: Any, runtime_framework: str) -> Any:
        """
        Resolve a model loader for a runtime descriptor string.
        """
        ...


# From exceptions
class DatasetSplitError:
    # Raised when expected dataset split directories/loaders are missing.

    ...

# From exceptions
class EvaluationError(Exception):
    # Base class for evaluation-related failures.

    ...

# From exceptions
class InferenceRunnerError:
    # Raised when runner execution or output coercion fails.

    ...

# From exceptions
class ModelLoadError:
    # Raised when model artifact loading fails.

    ...

# From exceptions
class PayloadFormatError:
    # Raised when metric payload does not satisfy schema.

    ...

# From exceptions
class RuntimeNotSupportedError:
    # Raised when task/runtime mapping is not configured.

    ...

# From inference_outputs
class ClassificationInferenceOutput:
    # Standard output container for classification-style runners.

    ...

# From inference_outputs
class DetectionInferenceOutput:
    # Standard output container for detection/segmentation-style runners.

    ...

# From inference_runners
class InferenceRunnerRegistry:
    # Registry used by evaluators to select framework-specific runners.

    def get(self: Any, runtime_key: str) -> Any | None:
        """
        Fetch a runner by exact runtime key when present.
        """
        ...

    def register(self: Any, runtime_key: str, runner: Any) -> None:
        """
        Register an inference runner under a runtime key.
        """
        ...

    def resolve(self: Any, runtime_framework: str) -> Any:
        """
        Resolve the best runner for a runtime descriptor string.
        """
        ...


# From orchestrator
class EvalContext:
    # Runtime context consumed by orchestrators.

    ...

# From orchestrator
class EvaluationOrchestrator:
    # Execute split evaluation and payload normalization.

    def fail(self: Any, error: Any) -> None:
        """
        Report evaluation failure details to tracking facilities.
        """
        ...

    def persist(self: Any, payload: Any) -> None:
        """
        Persist successful payload and emit completion status.
        """
        ...

    def run(self: Any) -> Any:
        """
        Execute evaluation over available splits and normalize payload.
        """
        ...


# From runtime_registry
class RuntimeTaskRegistry:
    # Registry keyed by task type and runtime framework.

    def register_loader(self: Any, task_type: str, runtime_key: str, loader: Any) -> None:
        """
        Register a model loader for a task/runtime pair.
        """
        ...

    def register_runner(self: Any, task_type: str, runtime_key: str, runner: Any) -> None:
        """
        Register an inference runner for a task/runtime pair.
        """
        ...

    def resolve_loader(self: Any, task_type: str, runtime_framework: str) -> Any:
        """
        Resolve a model loader callable for a task/runtime descriptor.
        """
        ...

    def resolve_runner(self: Any, task_type: str, runtime_framework: str) -> Any:
        """
        Resolve an inference runner callable for a task/runtime descriptor.
        """
        ...


# From schemas
class MetricRecord:
    # Metric record including optional contextual attributes.

    ...

# From schemas
class MetricRecordModel:
    # Pydantic schema used for metric payload validation.

    model_config: Any


# From status_handler
class EvaluationStatusCodes:
    # Canonical evaluation status step codes.

    ...

# From status_handler
class EvaluationStatusReporter:
    # Semantic status reporter for eval lifecycle transitions.

    def __init__(self: Any, action_tracker: Any, codes: Any | None = None) -> None:
        """
        Initialize status reporter with tracker and optional code overrides.
        """
        ...

    def acknowledged(self: Any, msg: str = 'Model Evaluation has acknowledged') -> None:
        """
        Publish acknowledgement status.
        """
        ...

    def completed(self: Any, msg: str = 'Model Evaluation is completed') -> None:
        """
        Publish evaluation-completed status.
        """
        ...

    def dataset_loaded(self: Any, msg: str = 'Evaluation dataset is loaded') -> None:
        """
        Publish dataset-ready status.
        """
        ...

    def failed(self: Any, msg: str) -> None:
        """
        Publish evaluation-failed status.
        """
        ...

    def model_loaded(self: Any, msg: str = 'Model loaded for evaluation') -> None:
        """
        Publish model-loaded status.
        """
        ...

    def started(self: Any, msg: str = 'Model Evaluation has started') -> None:
        """
        Publish evaluation-started status.
        """
        ...


from . import classification_runtime_adapters, common_classification, compat, contracts, dataset_utils, eval_model_loader, evaluator, exceptions, inference_outputs, inference_runners, orchestrator, result_formatter, runtime_registry, schemas, status_handler