from __future__ import annotations

from scripts.build_filtered_datasource_for_projects import (
    _extract_contract_supplier_ids,
    _supplier_identity_set,
)


def test_extract_contract_supplier_ids_prefers_supplier_id_then_company_id() -> None:
    contracts = [
        {"supplier_id": "sup-1", "company_id": "co-1"},
        {"company_id": "co-2"},
        {"supplier_id": "  ", "company_id": "co-3"},
        {"supplier_id": "sup-4"},
        {},
    ]

    assert _extract_contract_supplier_ids(contracts) == {"sup-1", "co-2", "co-3", "sup-4"}


def test_supplier_identity_set_includes_id_and__id() -> None:
    suppliers = [
        {"_id": "sup-1"},
        {"id": "sup-2"},
        {"_id": "sup-3", "id": "sup-3-alias"},
        {},
    ]

    assert _supplier_identity_set(suppliers) == {"sup-1", "sup-2", "sup-3", "sup-3-alias"}
