// Generated by smithplates HTTP codegen. Do not edit.

import { dumpApiModel } from "generated/petstore/api/petstore/modelValidation";
import { parseClientResponse } from "generated/petstore/api/petstore/client/clientResponse";
import { OPERATION_HTTP_BINDINGS } from "generated/petstore/api/petstore/client/operationBindings";
import type { HealthCheckOutput } from "generated/petstore/api/healthCheckOutput";

export class HealthApiClient {
  private readonly baseUrl: string;
  private readonly fetchFn: typeof fetch;

  constructor(baseUrl: string, fetchFn: typeof fetch = fetch) {
    this.baseUrl = baseUrl.replace(/\/+$/, "");
    this.fetchFn = fetchFn;
  }

  async healthCheck(
  ): Promise<HealthCheckOutput> {
    const headers: Record<string, string> = {};
    const queryParts: string[] = [];
    const queryString = queryParts.join("&");
    const requestUrl = `${this.baseUrl}/health` + (queryString ? "?" + queryString : "");
    const response = await this.fetchFn(
      requestUrl,
      {
        method: "GET",
        headers,
      },
    );
    const normalized = {
      status: response.status,
      headers: Object.fromEntries(response.headers.entries()),
      text: () => response.text(),
      json: async () => await response.json(),
    };
    const parsed = await parseClientResponse(normalized, OPERATION_HTTP_BINDINGS["healthCheck"]);
    return parsed as HealthCheckOutput;
  }
}
