import {
  BACKEND_API_ENDPOINT
} from "./chunk-XJ2RVBUZ.mjs";

// src/sdk/api/restApi.service.ts
import fetch from "cross-fetch";
import qs from "qs";
var RestApiService = class {
  async makeRequest(endpoint, method = "GET", queryParams = {}, body = null) {
    const queryString = qs.stringify(this.buildQueryParams(queryParams), { indices: false });
    const url = new URL(`${BACKEND_API_ENDPOINT}/${endpoint}?${queryString}`);
    const requestOptions = {
      method,
      headers: {
        "Content-Type": "application/json"
      },
      body: body ? JSON.stringify(body) : null
    };
    try {
      const response = await fetch(url.toString(), requestOptions);
      const data = await response.json();
      if (!response.ok) {
        if (response.status === 403) {
          throw new Error("Invalid API Key");
        }
        throw new Error(data.message || data.error || "Request failed");
      }
      return data;
    } catch (error) {
      throw new Error(error.message || "Something went wrong");
    }
  }
  buildQueryParams(params) {
    const queryParams = {};
    for (const key in params) {
      if (params.hasOwnProperty(key) && params[key] !== void 0 && params[key] !== null) {
        queryParams[key] = params[key];
      }
    }
    return queryParams;
  }
};

export {
  RestApiService
};
//# sourceMappingURL=chunk-D2QUIVVT.mjs.map