from __future__ import annotations

from enum import Enum


class PartitionKind(str, Enum):
    SNAPSHOTDATE = "snapshotdate"
    DATE = "date"
    NONPARTITIONED = "nonpartitioned"

    @classmethod
    def from_str(
        cls,
        value: str,
    ) -> PartitionKind:
        for kind in PartitionKind:
            if kind.value.lower() == value.lower():
                return kind
        raise ValueError(f"Unknown PartitionKind: {value}")

    @classmethod
    def from_any(
        cls,
        value: PartitionKind | str,
    ) -> PartitionKind:
        if isinstance(value, PartitionKind):
            return value
        return cls.from_str(value)

    @classmethod
    def list_all(cls) -> list[PartitionKind]:
        return [kind for kind in cls]

    def __str__(self) -> str:
        return self.value

    def __repr__(self) -> str:
        return f"{self.__class__.__name__}.{self.name}"
