"""Tests for Prometheus metrics endpoint."""

import pytest


@pytest.mark.asyncio
async def test_metrics_returns_200(client):
    resp = await client.get("/metrics")
    assert resp.status_code == 200
    assert "text/plain" in resp.headers["content-type"]


@pytest.mark.asyncio
async def test_metrics_contains_keys(client):
    resp = await client.get("/metrics")
    text = resp.text
    assert "guarddog_scans_total" in text
    assert "guarddog_scans_flagged_total" in text
    assert "guarddog_findings_total" in text
    assert "guarddog_scans_by_status" in text
    assert "guarddog_scans_by_ecosystem" in text
    # last_scan may not be present if no scans exist


@pytest.mark.asyncio
async def test_metrics_help_section(client):
    resp = await client.get("/metrics")
    assert "# HELP" in resp.text
    assert "# TYPE" in resp.text


@pytest.mark.asyncio
async def test_metrics_last_scan_with_data(client, sample_flagged_scan):
    resp = await client.get("/metrics")
    assert "guarddog_last_scan_timestamp_seconds" in resp.text
