import type { HistorianDashboardResponse } from "../../types/historian";

const API_BASE_URL = "http://localhost:18450";

export async function fetchHistorianDashboard(
  keys: string[],
  from: string,
  to: string,
): Promise<HistorianDashboardResponse> {
  const params = new URLSearchParams();

  keys.forEach((key) => params.append("keys", key));
  params.set("from", from);
  params.set("to", to);

  const response = await fetch(
    `${API_BASE_URL}/api/historian/dashboard?${params.toString()}`,
  );

  if (!response.ok) {
    throw new Error(`Failed to fetch historian dashboard: ${response.status}`);
  }

  return response.json();
}