package ai.decompile.docker.config;

import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.core.DockerClientBuilder;
import com.github.dockerjava.httpclient5.ApacheDockerHttpClient;
import java.net.URI;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(name = "app.docker.enabled", havingValue = "true", matchIfMissing = true)
public class DockerClientConfig {
  @Bean
  public DockerClient dockerClient(@Value("${app.die.docker-host}") String dockerHost) {
    var httpClient =
        new ApacheDockerHttpClient.Builder().dockerHost(URI.create(dockerHost)).build();

    return DockerClientBuilder.getInstance().withDockerHttpClient(httpClient).build();
  }
}
