/**
 * Auto-generated TypeScript client for x-gql API.
 * Generated by x-ranger site-docs from OpenAPI (route inventory).
 * Do not edit by hand — regenerate via `a0 xr deploy` / site docs.
 */

export interface ClientOptions {
  readonly baseUrl?: string;
  readonly fetch?: typeof globalThis.fetch;
  readonly headers?: Record<string, string>;
}

export class ApiClient {
  readonly baseUrl: string;
  readonly fetchImpl: typeof globalThis.fetch;
  readonly defaultHeaders: Record<string, string>;

  constructor(options: ClientOptions = {}) {
    this.baseUrl = (options.baseUrl ?? '').replace(/\/+$/, '');
    this.fetchImpl = options.fetch ?? globalThis.fetch.bind(globalThis);
    this.defaultHeaders = { ...(options.headers ?? {}) };
  }

  async request(
    method: string,
    path: string,
    init: RequestInit = {}
  ): Promise<Response> {
    const url = `${this.baseUrl}${path.startsWith("/") ? path : `/${path}`}`;
    const headers = { ...this.defaultHeaders, ...(init.headers as Record<string, string> | undefined) };
    return this.fetchImpl(url, { ...init, method, headers });
  }

  /** Resolve a knotchain federation record by chain id. */
  federationChain(init: RequestInit = {}): Promise<Response> {
    return this.request("GET", "/api/federationChain", init);
  }

  /** N1 two-step lookup (route + witness + admissible path proof). */
  federationLookup(init: RequestInit = {}): Promise<Response> {
    return this.request("GET", "/api/federationLookup", init);
  }

  /** Fetch signed federation index snapshot metadata. */
  federationSnapshot(init: RequestInit = {}): Promise<Response> {
    return this.request("GET", "/api/federationSnapshot", init);
  }

  /** Query: root → read_user */
  readUser(init: RequestInit = {}): Promise<Response> {
    return this.request("GET", "/api/readUser", init);
  }

  /** Mutation fold: input_user → save_user */
  saveUser(init: RequestInit = {}): Promise<Response> {
    return this.request("POST", "/api/saveUser", init);
  }

  /** Query: request → scan_result */
  scanResult(init: RequestInit = {}): Promise<Response> {
    return this.request("GET", "/api/scanResult", init);
  }

}

export default ApiClient;
