package ai.decompile.ai.service;

import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.log4j.Log4j2;
import org.springframework.ai.ollama.OllamaEmbeddingModel;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.resilience.annotation.Retryable;
import org.springframework.stereotype.Component;

@Log4j2
@Component
@RequiredArgsConstructor
@ConditionalOnProperty(name = "app.ai.enabled", havingValue = "true", matchIfMissing = true)
public class OllamaEmbeddingClient implements EmbeddingClient {
  private final OllamaEmbeddingModel embeddingModel;

  @Override
  @Retryable(maxRetries = 2, delay = 500, multiplier = 2)
  public float[] embed(String text) {
    return embeddingModel.embed(text);
  }

  @Override
  public List<float[]> embed(List<String> texts) {
    return embeddingModel.embed(texts);
  }
}
