package at.procon.dip.embedding.service;

import at.procon.dip.embedding.config.EmbeddingProfileProperties;
import at.procon.dip.embedding.policy.EmbeddingProfile;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class DefaultEmbeddingProfileResolver implements EmbeddingProfileResolver {

    private final EmbeddingProfileProperties properties;

    @Override
    public EmbeddingProfile resolve(String profileKey) {
        if (profileKey == null || profileKey.isBlank()) {
            throw new IllegalArgumentException("Embedding profile key must not be blank");
        }

        EmbeddingProfileProperties.ProfileDefinition definition = properties.getDefinitions().get(profileKey);
        if (definition == null) {
            throw new IllegalArgumentException("Unknown embedding profile: " + profileKey);
        }

        return new EmbeddingProfile(
                profileKey,
                List.copyOf(definition.getEmbedRepresentationTypes())
        );
    }
}
