from enum import StrEnum

from olmoearth_shared.models.datasets.data_provider_name import DataProviderName
from prometheus_client import Counter


class Outcome(StrEnum):
    SUCCESS = "success"
    FAILURE = "failure"

_ingest_attempts_counter = Counter(
    "runner_olmoearth_datasets_ingest_attempts_total",
    "Asset ingest attempts by provider, with outcome",
    labelnames=["provider", "outcome"],
)


class OlmoEarthDatasetsMetrics:
    """Metrics for OlmoEarthDatasets data source operations."""

    @staticmethod
    def record_ingest_attempt(provider: DataProviderName, outcome: Outcome) -> None:
        """Record an asset ingest attempt."""
        _ingest_attempts_counter.labels(
            provider=provider.value,
            outcome=outcome,
        ).inc()

    @staticmethod
    def get_ingest_attempt_count(provider: DataProviderName, outcome: Outcome) -> float:
        """Get the current ingest attempt count for a provider and outcome."""
        return _ingest_attempts_counter.labels(
            provider=provider.value,
            outcome=outcome,
        )._value.get()
