from typing import Any


def target_present(test_result: dict) -> Any:
    """
    Returns a value for ``warehouse.presence_absence.present``
    for the given received *test_result*, or ``...``
    (``Ellipsis``) if the test should be skipped.

    Raises a :py:class:`ValueError` if a value cannot be determined.
    """
    status = (
           test_result.get("targetStatus")
        or test_result.get("sampleState")
    )

    mapping = {
        "Detected": True,
        "NotDetected": False,

        "Positive": True,
        "PositiveControlPass": True,
        "Negative": False,
        "Indeterminate": None,
        "Inconclusive": None,

        # These are valid _workflow_ statuses, but they're not really test
        # results; they describe the circumstances around performing the test,
        # not the result of the test itself.  We skip ingesting them for now as
        # there is no place for them in our current data model.
        #
        # I did consider making these map to None/null like Indeterminate.
        # That would make "present is null" results in the database mean "this
        # test was run, but the result is unknown due to circumstances left
        # unspecified".  I ultimately decided against it as the goal with ID3C
        # is to aim for simpler data models which are easier to reckon about,
        # not track everything that's performed like a LIMS/LIS does.
        #   -trs, 20 Mar 2020
        "Fail": ...,
        "Repeat": ...,
        "Review": ...,
    }

    if not status or status not in mapping:
        raise ValueError(f"Unable to determine target presence given «{test_result}»")

    return mapping[status]