package at.procon.dip.embedding.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import at.procon.dip.domain.document.RepresentationType;
import at.procon.dip.embedding.config.EmbeddingProfileProperties;
import java.util.List;
import org.junit.jupiter.api.Test;

class DefaultEmbeddingProfileResolverTest {

    @Test
    void shouldResolveKnownProfile() {
        EmbeddingProfileProperties properties = new EmbeddingProfileProperties();
        EmbeddingProfileProperties.ProfileDefinition def = new EmbeddingProfileProperties.ProfileDefinition();
        def.setEmbedRepresentationTypes(List.of(RepresentationType.SEMANTIC_TEXT, RepresentationType.CHUNK));
        properties.getDefinitions().put("primary-and-chunks", def);

        DefaultEmbeddingProfileResolver resolver = new DefaultEmbeddingProfileResolver(properties);

        var profile = resolver.resolve("primary-and-chunks");

        assertThat(profile.profileKey()).isEqualTo("primary-and-chunks");
        assertThat(profile.embedRepresentationTypes()).containsExactly(RepresentationType.SEMANTIC_TEXT, RepresentationType.CHUNK);
    }

    @Test
    void shouldFailForUnknownProfile() {
        EmbeddingProfileProperties properties = new EmbeddingProfileProperties();
        DefaultEmbeddingProfileResolver resolver = new DefaultEmbeddingProfileResolver(properties);

        assertThatThrownBy(() -> resolver.resolve("missing"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("Unknown embedding profile");
    }
}
