from uuid import uuid4

from src.domain.usage.hosted_app_analytics import parse_hosted_app_usage_rows


def test_parse_hosted_app_usage_rows_reads_analytics_engine_totals() -> None:
    project_id = uuid4()

    result = parse_hosted_app_usage_rows(
        {
            "data": [
                {
                    "project_id": str(project_id),
                    "hosted_app_requests": "12",
                    "hosted_app_egress_bytes": "1024.9",
                }
            ]
        }
    )

    assert result == {
        project_id: {"hosted_app_requests": 12, "hosted_app_egress_bytes": 1024}
    }


def test_parse_hosted_app_usage_rows_ignores_invalid_project_ids() -> None:
    assert parse_hosted_app_usage_rows(
        {"data": [{"project_id": "not-a-uuid", "hosted_app_requests": 1}]}
    ) == {}
