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

import { dumpApiModel } from "generated/example/chatApi/modelValidation";
import { parseClientResponse } from "generated/example/chatApi/client/clientResponse";
import { OPERATION_HTTP_BINDINGS } from "generated/example/chatApi/client/operationBindings";
import type { RoomListOutput } from "generated/example/roomListOutput";

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

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

  async listRooms(
  ): Promise<RoomListOutput> {
    const headers: Record<string, string> = {};
    const queryParts: string[] = [];
    const queryString = queryParts.join("&");
    const requestUrl = `${this.baseUrl}/rooms` + (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["listRooms"]);
    return parsed as RoomListOutput;
  }
}
