// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/model/Image.java
// public class Image {
// 
//     private final String digest;
// 
//     @JsonProperty("last_modified")
//     private final Date lastModified;
// 
//     public Image(String digest, Date last_modified) {
//         this.digest = digest;
//         this.lastModified = last_modified;
//     }
// 
//     public String getDigest() {
//         return digest;
//     }
// 
//     public Date getLastModified() {
//         return lastModified;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         Image image = (Image) o;
//         return Objects.equals(digest, image.digest) &&
//                 Objects.equals(lastModified, image.lastModified);
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(digest, lastModified);
//     }
// }


import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import io.crate.spring.jdbc.samples.model.Image;
package io.crate.spring.jdbc.samples.dao;




@Component
public class ImagesJDBCTemplateDao implements ImagesDao {

    @Value("${cratesample.cratedb.blobEndpointURL:http://localhost:4200/_blobs/}")
    private String blobEndpointURL;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    private HttpClient client = HttpClient.newHttpClient();

    @Override
    public boolean imageExists(@NonNull final String digest) {
        var request = HttpRequest
                .newBuilder(this.createBlobUri(digest))
                .method("HEAD", HttpRequest.BodyPublishers.noBody())
                .build();
        try {
            var response = client.send(request, HttpResponse.BodyHandlers.discarding());
            return response.statusCode() == HttpStatus.OK.value();
        } catch (IOException | InterruptedException e) {
            throw new DataIntegrityViolationException("Failed to call blob endpoint", e);
        }
    }

    @Override
// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/model/Image.java
// public class Image {
// 
//     private final String digest;
// 
//     @JsonProperty("last_modified")
//     private final Date lastModified;
// 
//     public Image(String digest, Date last_modified) {
//         this.digest = digest;
//         this.lastModified = last_modified;
//     }
// 
//     public String getDigest() {
//         return digest;
//     }
// 
//     public Date getLastModified() {
//         return lastModified;
//     }
// 
//     @Override
//     public boolean equals(Object o) {
//         if (this == o) return true;
//         if (o == null || getClass() != o.getClass()) return false;
//         Image image = (Image) o;
//         return Objects.equals(digest, image.digest) &&
//                 Objects.equals(lastModified, image.lastModified);
//     }
// 
//     @Override
//     public int hashCode() {
//         return Objects.hash(digest, lastModified);
//     }
// }


// Path: spring-jdbc/src/main/java/io/crate/spring/jdbc/samples/dao/ImagesJDBCTemplateDao.java
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.lang.NonNull;
import org.springframework.stereotype.Component;
import io.crate.spring.jdbc.samples.model.Image;

package io.crate.spring.jdbc.samples.dao;




@Component
public class ImagesJDBCTemplateDao implements ImagesDao {

    @Value("${cratesample.cratedb.blobEndpointURL:http://localhost:4200/_blobs/}")
    private String blobEndpointURL;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    private HttpClient client = HttpClient.newHttpClient();

    @Override
    public boolean imageExists(@NonNull final String digest) {
        var request = HttpRequest
                .newBuilder(this.createBlobUri(digest))
                .method("HEAD", HttpRequest.BodyPublishers.noBody())
                .build();
        try {
            var response = client.send(request, HttpResponse.BodyHandlers.discarding());
            return response.statusCode() == HttpStatus.OK.value();
        } catch (IOException | InterruptedException e) {
            throw new DataIntegrityViolationException("Failed to call blob endpoint", e);
        }
    }

    @Override
    public List<Image> getImages() {