"""DatasetAdapter — uniform interface for e2e harness over arbitrary UAV datasets."""

from __future__ import annotations

from abc import ABC, abstractmethod
from dataclasses import dataclass
from enum import Enum
from typing import Iterator


class PlatformClass(str, Enum):
    FIXED_WING = "fixed_wing"
    ROTARY = "rotary"
    INDOOR = "indoor"
    SYNTHETIC = "synthetic"


class DatasetNotAvailableError(RuntimeError):
    """Raised when a dataset's expected files are missing. Tests should skip, not fail."""


@dataclass(frozen=True)
class DatasetCapabilities:
    has_raw_imu: bool
    has_rtk_gt: bool
    has_loop_closures: bool
    platform_class: PlatformClass


@dataclass(frozen=True)
class DatasetFrame:
    frame_idx: int
    timestamp_ns: int
    image_path: str


@dataclass(frozen=True)
class DatasetIMU:
    timestamp_ns: int
    accel: tuple[float, float, float]  # m/s^2 in body frame
    gyro: tuple[float, float, float]   # rad/s in body frame


@dataclass(frozen=True)
class DatasetPose:
    timestamp_ns: int
    lat: float
    lon: float
    alt: float
    qx: float
    qy: float
    qz: float
    qw: float


class DatasetAdapter(ABC):
    """Uniform read-only iteration over a UAV dataset."""

    @property
    @abstractmethod
    def name(self) -> str: ...

    @property
    @abstractmethod
    def capabilities(self) -> DatasetCapabilities: ...

    @abstractmethod
    def iter_frames(self) -> Iterator[DatasetFrame]: ...

    @abstractmethod
    def iter_imu(self) -> Iterator[DatasetIMU]: ...

    @abstractmethod
    def iter_ground_truth(self) -> Iterator[DatasetPose]: ...
