library(httr2)
library(jsonlite)

base_url <- Sys.getenv("BATTERYARB_BASE_URL", "https://api.richbuilds.net")
api_key <- Sys.getenv("BATTERYARB_API_KEY")

get_json <- function(path) {
  request(paste0(base_url, path)) |>
    req_headers(`X-API-Key` = api_key) |>
    req_perform() |>
    resp_body_string() |>
    fromJSON()
}

print(get_json("/health"))
print(get_json("/markets/supported"))
print(get_json("/prices/lmp-5min?iso=ercot&lookback_hours=24"))
print(get_json("/grid/outages?iso=ercot"))
print(get_json("/forecast/lmp?iso=ercot&horizon_hours=24"))
print(get_json("/battery/arbitrage?iso=ercot&battery_duration_hours=2&efficiency=0.9"))
print(get_json("/battery/bid-offer-sim?iso=ercot&lookback_hours=24&bid_charge_usd_mwh=25&offer_discharge_usd_mwh=65"))
print(get_json("/battery/edge-signal?iso=ercot&horizon_hours=24"))
