from promrs import CollectorRegistry, Gauge, generate_latest


def test_gauge_set() -> None:
    registry = CollectorRegistry()
    g = Gauge("temperature", "Current temperature", ["location"], registry=registry)
    g.labels(location="office").set(22.5)
    output = generate_latest(registry).decode()
    assert 'temperature{location="office"} 22.5' in output


def test_gauge_inc() -> None:
    registry = CollectorRegistry()
    g = Gauge("connections", "Active connections", ["pool"], registry=registry)
    g.labels(pool="main").inc()
    g.labels(pool="main").inc()
    output = generate_latest(registry).decode()
    assert 'connections{pool="main"} 2.0' in output


def test_gauge_dec() -> None:
    registry = CollectorRegistry()
    g = Gauge("connections", "Active connections", ["pool"], registry=registry)
    g.labels(pool="main").set(10.0)
    g.labels(pool="main").dec()
    g.labels(pool="main").dec(3.0)
    output = generate_latest(registry).decode()
    assert 'connections{pool="main"} 6.0' in output


def test_gauge_inc_by() -> None:
    registry = CollectorRegistry()
    g = Gauge("gauge_test", "test", ["k"], registry=registry)
    g.labels(k="v").inc(5.5)
    output = generate_latest(registry).decode()
    assert 'gauge_test{k="v"} 5.5' in output


def test_gauge_multiple_labels() -> None:
    registry = CollectorRegistry()
    g = Gauge("cpu_usage", "CPU usage", ["host", "core"], registry=registry)
    g.labels(host="srv1", core="0").set(45.2)
    g.labels(host="srv1", core="1").set(30.1)
    output = generate_latest(registry).decode()
    assert 'cpu_usage{core="0",host="srv1"} 45.2' in output
    assert 'cpu_usage{core="1",host="srv1"} 30.1' in output
