package com.developx.szpitale.ingest.source;

import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.*;

class PwzRegistrySourceTest {

    @Test
    void lookupPwz_singleMatch_returnsPwzNumber() {
        PwzLookupClient client = fullName -> List.of("1234567");
        PwzRegistrySource source = new PwzRegistrySource(client);

        Optional<String> result = source.lookupPwz("Jan Kowalski");

        assertTrue(result.isPresent());
        assertEquals("1234567", result.get());
    }

    @Test
    void lookupPwz_multipleMatches_returnsEmpty() {
        PwzLookupClient client = fullName -> List.of("1234567", "7654321");
        PwzRegistrySource source = new PwzRegistrySource(client);

        Optional<String> result = source.lookupPwz("Jan Kowalski");

        assertFalse(result.isPresent(), "Multiple matches should return empty (ambiguity)");
    }

    @Test
    void lookupPwz_noMatch_returnsEmpty() {
        PwzLookupClient client = fullName -> List.of();
        PwzRegistrySource source = new PwzRegistrySource(client);

        Optional<String> result = source.lookupPwz("Jan Kowalski");

        assertFalse(result.isPresent(), "No match should return empty");
    }

    @Test
    void lookupPwz_nullClient_returnsEmpty() {
        PwzRegistrySource source = new PwzRegistrySource(null);

        Optional<String> result = source.lookupPwz("Jan Kowalski");

        assertFalse(result.isPresent());
    }
}
