#!/usr/bin/env python3
"""
Test du filtre EPISODE pour les documents trackare.
"""

import sys
sys.path.insert(0, '.')

from detectors.hospital_filter import HospitalFilter

# Test cases from the analysis
test_cases = [
    # (pii_type, text, filename, is_trackare, expected_filtered)
    ("EPISODE", "23095226", "trackare-02016820-23095226_02016820_23095226.pdf", True, True),
    ("EPISODE", "23074384", "trackare-15000536-23074384_15000536_23074384.pdf", True, True),
    ("EPISODE", "23183041", "trackare-10027557-23183041_10027557_23183041.pdf", True, True),
    ("EPISODE", "23066188", "trackare-17001141-23066188_17001141_23066188.pdf", True, True),
    ("EPISODE", "23202435", "trackare-14004105-23202435_14004105_23202435.pdf", True, True),
    ("EPISODE", "N° Episode 23102610", "CRH_23102610.pdf", False, False),
    ("EPISODE", "N° Episode 23042753", "CRH_23042753.pdf", False, False),
    ("EPISODE", "23102610", "CRH_23102610.pdf", False, False),
]

filter = HospitalFilter()

print("Test du filtre EPISODE:")
print("=" * 100)

for pii_type, text, filename, is_trackare, expected_filtered in test_cases:
    # Test 1: should_filter method
    result = filter.should_filter(pii_type, text, filename)
    status = "✅" if result == expected_filtered else "❌"
    print(f"{status} should_filter: {pii_type:10s} '{text:25s}' filename='{filename:50s}' -> {result} (attendu: {expected_filtered})")
    
    # Test 2: filter_detections method (simulating real usage)
    detections = [{'kind': pii_type, 'original': text, 'page': 0}]
    filtered = filter.filter_detections(detections, filename, is_trackare=is_trackare)
    was_filtered = len(filtered) == 0
    status2 = "✅" if was_filtered == expected_filtered else "❌"
    print(f"{status2} filter_detections: is_trackare={is_trackare} -> filtered={was_filtered} (attendu: {expected_filtered})")
    print()
