from rights_filter.admin.correction_handlers import correct_rejected_decision
from rights_filter.admin.knowledge_base_handlers import register_manual_entry
from rights_filter.domain.records import (
    InMemoryRightsFilterRepository,
    KnowledgeEntryType,
    ReviewStatus,
)
from rights_filter.admin.review_handlers import record_operator_decision


def test_correcting_rejection_deactivates_only_derived_entries():
    repo = InMemoryRightsFilterRepository()
    decision = record_operator_decision(
        repo,
        "submission-1",
        ReviewStatus.REJECTED,
        fingerprints=["phash:auto"],
    )
    manual = register_manual_entry(
        repo,
        entry_type=KnowledgeEntryType.CELEBRITY,
        name="IU",
        sample_fingerprints=["phash:manual"],
    )

    deactivated = correct_rejected_decision(
        repo,
        decision.id,
        reason="operator corrected false positive",
    )

    assert len(deactivated) == 1
    assert deactivated[0].source_decision_id == decision.id
    assert deactivated[0].active is False
    assert repo.knowledge_entry(manual.id).active is True
