import math

from promrs import CONTENT_TYPE_LATEST, CollectorRegistry, Counter, Gauge, Histogram, generate_latest


def test_content_type_latest() -> None:
    assert CONTENT_TYPE_LATEST == "application/openmetrics-text; version=1.0.0; charset=utf-8"


def test_default_buckets_classattr() -> None:
    buckets = Histogram.DEFAULT_BUCKETS
    assert isinstance(buckets, list)
    assert len(buckets) == 15
    assert buckets[0] == 0.005
    assert buckets[-2] == 10.0
    assert math.isinf(buckets[-1])


def test_documentation_param_name() -> None:
    registry = CollectorRegistry()
    Counter("doc_counter", documentation="My help text", registry=registry)
    output = generate_latest(registry).decode()
    assert "# HELP doc_counter My help text." in output


def test_labelnames_param_name() -> None:
    registry = CollectorRegistry()
    c = Counter("ln_counter", "test", labelnames=["method"], registry=registry)
    c.labels(method="GET").inc()
    output = generate_latest(registry).decode()
    assert 'ln_counter_total{method="GET"} 1.0' in output


def test_labelnames_defaults_to_empty() -> None:
    registry = CollectorRegistry()
    c = Counter("empty_labels_counter", "test", registry=registry)
    c.inc()
    output = generate_latest(registry).decode()
    assert "empty_labels_counter_total{} 1.0" in output


def test_counter_is_subclass_of_rust_counter() -> None:
    from promrs._promrs import Counter as RustCounter

    assert issubclass(Counter, RustCounter)


def test_gauge_is_subclass_of_rust_gauge() -> None:
    from promrs._promrs import Gauge as RustGauge

    assert issubclass(Gauge, RustGauge)


def test_histogram_is_subclass_of_rust_histogram() -> None:
    from promrs._promrs import Histogram as RustHistogram

    assert issubclass(Histogram, RustHistogram)
