package com.developx.szpitale.ingest.source;

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

public class PwzRegistrySource {

    private final PwzLookupClient client;

    public PwzRegistrySource(PwzLookupClient client) {
        this.client = client;
    }

    public Optional<String> lookupPwz(String fullName) {
        if (client == null || fullName == null || fullName.isBlank()) {
            return Optional.empty();
        }

        List<String> results = client.query(fullName);

        if (results == null || results.isEmpty()) {
            return Optional.empty();
        }

        if (results.size() == 1) {
            return Optional.of(results.get(0));
        }

        return Optional.empty();
    }
}
