package de.gecheckt.pdf.umbenenner.application.port.out.modelcatalog;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatNullPointerException;

import java.util.Optional;

import org.junit.jupiter.api.Test;

/**
 * Tests for {@link ModelCatalogRequest}.
 */
class ModelCatalogRequestTest {

    @Test
    void storesAllProvidedValues() {
        var request = new ModelCatalogRequest(
                "claude",
                Optional.of("https://api.anthropic.com"),
                Optional.of("test-key"),
                30);

        assertThat(request.providerIdentifier()).isEqualTo("claude");
        assertThat(request.baseUrl()).contains("https://api.anthropic.com");
        assertThat(request.apiKey()).contains("test-key");
        assertThat(request.timeoutSeconds()).isEqualTo(30);
    }

    @Test
    void nullBaseUrlBecomesEmpty() {
        var request = new ModelCatalogRequest("claude", null, Optional.of("key"), 10);
        assertThat(request.baseUrl()).isEmpty();
    }

    @Test
    void nullApiKeyBecomesEmpty() {
        var request = new ModelCatalogRequest("claude", Optional.empty(), null, 10);
        assertThat(request.apiKey()).isEmpty();
    }

    @Test
    void rejectsNullProviderIdentifier() {
        assertThatNullPointerException()
                .isThrownBy(() -> new ModelCatalogRequest(null, Optional.empty(), Optional.empty(), 10));
    }

    @Test
    void rejectsZeroTimeout() {
        assertThatIllegalArgumentException()
                .isThrownBy(() -> new ModelCatalogRequest("claude", Optional.empty(), Optional.empty(), 0));
    }

    @Test
    void rejectsNegativeTimeout() {
        assertThatIllegalArgumentException()
                .isThrownBy(() -> new ModelCatalogRequest("claude", Optional.empty(), Optional.empty(), -5));
    }
}
