"""Tests for the ImportService protocol and IMPORT_REGISTRY."""

from app.domain.ports.import_service import (
    IMPORT_REGISTRY,
    ImportService,
    ImportServiceEntry,
    get_import_handler,
)


def test_registry_has_all_known_sources():
    expected = {
        "atomic_red_team",
        "sigma",
        "lolbas",
        "gtfobins",
        "caldera",
        "elastic_rules",
        "mitre_cti",
        "d3fend",
    }
    assert set(IMPORT_REGISTRY.keys()) == expected


def test_all_entries_are_import_service_entries():
    for name, entry in IMPORT_REGISTRY.items():
        assert isinstance(entry, ImportServiceEntry), f"{name} is not ImportServiceEntry"


def test_get_import_handler_returns_entry_for_known_source():
    handler = get_import_handler("sigma")
    assert handler is not None
    assert isinstance(handler, ImportServiceEntry)


def test_get_import_handler_returns_none_for_unknown():
    assert get_import_handler("nonexistent_source") is None


def test_import_service_entry_source_info():
    entry = ImportServiceEntry("app.services.sigma_import_service", "sync")
    assert entry.source_info == "app.services.sigma_import_service.sync"


def test_callable_satisfies_protocol():
    def mock_handler(db):
        return {"created": 0}

    assert isinstance(mock_handler, ImportService)
