"""Tests for inspect.short_state."""

from __future__ import annotations

from gsc.inspect import short_state


def test_extracts_all_fields() -> None:
    payload = {
        "inspectionResult": {
            "indexStatusResult": {
                "verdict": "PASS",
                "coverageState": "Submitted and indexed",
                "robotsTxtState": "ALLOWED",
                "indexingState": "INDEXING_ALLOWED",
                "pageFetchState": "SUCCESSFUL",
                "googleCanonical": "https://example.com/a",
                "userCanonical": "https://example.com/a",
                "lastCrawlTime": "2026-05-20T10:00:00Z",
            }
        }
    }
    assert short_state(payload) == {
        "verdict": "PASS",
        "coverageState": "Submitted and indexed",
        "robotsTxtState": "ALLOWED",
        "indexingState": "INDEXING_ALLOWED",
        "pageFetchState": "SUCCESSFUL",
        "googleCanonical": "https://example.com/a",
        "userCanonical": "https://example.com/a",
        "lastCrawlTime": "2026-05-20T10:00:00Z",
    }


def test_missing_keys_yield_none() -> None:
    result = short_state({})
    assert result == {
        "verdict": None,
        "coverageState": None,
        "robotsTxtState": None,
        "indexingState": None,
        "pageFetchState": None,
        "googleCanonical": None,
        "userCanonical": None,
        "lastCrawlTime": None,
    }


def test_partial_index_status() -> None:
    payload = {
        "inspectionResult": {
            "indexStatusResult": {
                "verdict": "FAIL",
                "coverageState": "Discovered - currently not indexed",
            }
        }
    }
    state = short_state(payload)
    assert state["verdict"] == "FAIL"
    assert state["coverageState"] == "Discovered - currently not indexed"
    assert state["lastCrawlTime"] is None
    assert state["pageFetchState"] is None


def test_non_dict_input_returns_none_fields() -> None:
    assert short_state("not a dict")["verdict"] is None  # type: ignore[arg-type]
    assert short_state(None)["coverageState"] is None  # type: ignore[arg-type]
