from enum import StrEnum
from typing import Self

from pydantic import BaseModel, Field, model_validator


class SpaceMode(StrEnum):
    """How to build up or sample imagery."""

    MOSAIC = "mosaic"
    CONTAINS = "contains"


class Sentinel2L2ASortBy(StrEnum):
    CLOUD_COVER = "cloud_cover"


class Sentinel2L2A(BaseModel):
    sort_by: Sentinel2L2ASortBy = Field(default=Sentinel2L2ASortBy.CLOUD_COVER, description="The field to sort the data by.")
    space_mode: SpaceMode


class Sentinel1RTCOrbitDirection(StrEnum):
    ASCENDING_ORBIT = "ascending_orbit"
    DESCENDING_ORBIT = "descending_orbit"


class Sentinel1RTC(BaseModel):
    orbit_direction: Sentinel1RTCOrbitDirection = Field(default=Sentinel1RTCOrbitDirection.ASCENDING_ORBIT, description="The direction of the orbit.")
    space_mode: SpaceMode


# TODO: landsat8/9


Modality = Sentinel2L2A | Sentinel1RTC


class Modalities(BaseModel):
    sentinel2_l2a: Sentinel2L2A | None = None
    sentinel1_rtc: Sentinel1RTC | None = None

    @model_validator(mode="after")
    def validate_at_least_one_modality(self) -> Self:
        if self.sentinel2_l2a is None and self.sentinel1_rtc is None:
            raise ValueError("At least one modality must be specified")
        return self
