package com.rdkr.tide_display.backend.images.services.mapProvider;

import com.rdkr.tide_display.backend.apple.Snapshot;
import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

@Component("AppleMapKit")
@RequiredArgsConstructor
public class AppleMapKit implements MapProvider {

  private final RestClient.Builder restClient;
  private final Snapshot snapshot;

  @Override
  public byte[] getStaticMap(double latitude, double longitude, int zoom) {
    try {
      val uri = snapshot.generateSnapshotURI(latitude, longitude);
      val client = restClient.baseUrl(uri.toString()).build();
      return client.get()
          .retrieve()
          .body(byte[].class);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
  }

}
