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


def test_registry_is_collector_registry() -> None:
    assert isinstance(REGISTRY, CollectorRegistry)


def test_counter_default_registry() -> None:
    registry = CollectorRegistry()
    c = Counter("default_counter", "test", ["k"], registry=registry)
    c.labels(k="v").inc()
    output = generate_latest(registry).decode()
    assert 'default_counter_total{k="v"} 1.0' in output


def test_gauge_default_registry() -> None:
    registry = CollectorRegistry()
    g = Gauge("default_gauge", "test", ["k"], registry=registry)
    g.labels(k="v").set(42.0)
    output = generate_latest(registry).decode()
    assert 'default_gauge{k="v"} 42.0' in output


def test_histogram_default_registry() -> None:
    registry = CollectorRegistry()
    h = Histogram("default_hist", "test", ["k"], registry=registry, buckets=[1.0, 5.0])
    h.labels(k="v").observe(0.5)
    output = generate_latest(registry).decode()
    assert "default_hist" in output


def test_generate_latest_no_args_uses_default_registry() -> None:
    output = generate_latest()
    assert isinstance(output, bytes)
    assert output.decode().endswith("# EOF\n")


def test_custom_registry_isolation() -> None:
    custom = CollectorRegistry()
    Counter("isolated_counter", "test", ["k"], registry=custom)
    output = generate_latest(custom).decode()
    assert "isolated_counter" in output
    # Default REGISTRY should NOT contain this metric
    default_output = generate_latest().decode()
    assert "isolated_counter" not in default_output
