"""The plain-language line a reference carries for its status, and the
label that names what a source is without the status code."""

from quber.core.extractors.base import CELL_STATUS_REFERENCE
from quber.playground.app import _label, _reason


def test_every_registry_label_reads_as_a_sentence():
    for s in CELL_STATUS_REFERENCE:
        assert s.label[0].isupper() and s.label.endswith("."), s.code
        assert "_" not in s.label, s.code


def test_reason_is_the_registry_label():
    reason, printed = _reason("value_unreconciled", "one measurement, read from the page", "4%")
    assert reason == "Read from the chart once, without a second check. Worth a manual look."
    assert printed is None


def test_misread_names_both_figures():
    note = "the page prints '6%' where this value should appear - possible misread"
    reason, printed = _reason("value_misread", note, "11%")
    assert reason == "The page prints 6% here, not 11%. Check which is right."
    assert printed == "6%"


def test_misread_reads_the_fragment_shape_too():
    reason, printed = _reason("value_misread", "fragment at the value's position prints '~ 87%'", "~87%")
    assert reason == "The page prints ~ 87% here, not ~87%. Check which is right."
    assert printed == "~ 87%"


def test_misread_without_a_parsable_note_falls_back_to_the_label():
    reason, printed = _reason("value_misread", "no printed figure recorded", "11%")
    assert reason == "The page prints a different figure here. Check which is right."
    assert printed is None


def test_no_status_means_no_reason():
    assert _reason(None, None, "$1") == (None, None)


def test_label_never_carries_the_status_code():
    for status in ("reconciled", "defect", "value_misread", None):
        assert _label("tableCell", 6, status) == "Page 6, table cell"
    assert _label("figureValue", 12) == "Page 12, chart value"
    assert _label("line_item", 3) == "Page 3, table row"
    assert _label("text", 2) == "Page 2, text"
