from rights_filter.domain.records import DataClass
from rights_filter.governance.policies import (
    GovernancePolicyRegistry,
    assert_no_biometric_template,
    assert_operator_evidence_payload_allowed,
)


def test_each_data_class_has_access_retention_delete_and_correction_policy():
    registry = GovernancePolicyRegistry.default()

    for data_class in DataClass:
        policy = registry.policy_for(data_class)
        assert policy.access_roles
        assert policy.retention
        assert policy.deletion
        assert policy.correction


def test_biometric_template_storage_is_rejected():
    try:
        assert_no_biometric_template({"embedding": [0.1, 0.2, 0.3]})
    except ValueError as error:
        assert "biometric template" in str(error)
    else:
        raise AssertionError("expected biometric template rejection")


def test_search_evidence_rejects_image_payloads_sent_to_naver():
    try:
        assert_operator_evidence_payload_allowed(
            DataClass.SEARCH_EVIDENCE,
            {
                "provider": "naver",
                "query": "IU album cover",
                "original_image": b"raw-image-bytes",
            },
        )
    except ValueError as error:
        assert "image payload" in str(error)
    else:
        raise AssertionError("expected Naver image payload rejection")


def test_llm_summary_must_reference_source_evidence():
    try:
        assert_operator_evidence_payload_allowed(
            DataClass.LLM_SUMMARY,
            {
                "summary": "This appears to be a famous character.",
                "source_urls": [],
                "source_evidence_ids": [],
            },
        )
    except ValueError as error:
        assert "source evidence" in str(error)
    else:
        raise AssertionError("expected source evidence rejection")
