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

import lombok.RequiredArgsConstructor;
import lombok.val;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClient;

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

  private final RestClient.Builder restClient;

  @Value("${MAPBOX_TOKEN:dummy}")
  private String accessToken;

  @Override
  public byte[] getStaticMap(double latitude, double longitude, int zoom) {
    val client = restClient.baseUrl("https://api.mapbox.com/styles/v1/mapbox/streets-v12/static").build();
    return client.get()
        .uri(builder -> builder
            .path("/" + longitude + "," + latitude + "," + (zoom - 1))
            .path("/540x540")
            .queryParam("access_token", accessToken)
            .build())
        .retrieve()
        .body(byte[].class);
  }

}
