/**
 * Generated by orval 🍺
 * Do not edit manually.
 * messages API
 * This is the messages API schema.
 * OpenAPI spec version: 1.0.0 (v1.0)
 */
import { useQuery } from "@tanstack/react-query";
import type {
  DataTag,
  DefinedInitialDataOptions,
  DefinedUseQueryResult,
  QueryClient,
  QueryFunction,
  QueryKey,
  UndefinedInitialDataOptions,
  UseQueryOptions,
  UseQueryResult,
} from "@tanstack/react-query";

import type { ConfigRetrieve200 } from ".././models";

import { fetchAPI } from "../../fetch-api";
import type { ErrorType } from "../../fetch-api";

type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];

/**
 * Return a dictionary of public settings for the frontend to consume.
 */
export type configRetrieveResponse200 = {
  data: ConfigRetrieve200;
  status: 200;
};

export type configRetrieveResponseSuccess = configRetrieveResponse200 & {
  headers: Headers;
};
export type configRetrieveResponse = configRetrieveResponseSuccess;

export const getConfigRetrieveUrl = () => {
  return `/api/v1.0/config/`;
};

export const configRetrieve = async (
  options?: RequestInit,
): Promise<configRetrieveResponse> => {
  return fetchAPI<configRetrieveResponse>(getConfigRetrieveUrl(), {
    ...options,
    method: "GET",
  });
};

export const getConfigRetrieveQueryKey = () => {
  return [`/api/v1.0/config/`] as const;
};

export const getConfigRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof configRetrieve>>,
  TError = ErrorType<unknown>,
>(options?: {
  query?: Partial<
    UseQueryOptions<Awaited<ReturnType<typeof configRetrieve>>, TError, TData>
  >;
  request?: SecondParameter<typeof fetchAPI>;
}) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey = queryOptions?.queryKey ?? getConfigRetrieveQueryKey();

  const queryFn: QueryFunction<Awaited<ReturnType<typeof configRetrieve>>> = ({
    signal,
  }) => configRetrieve({ signal, ...requestOptions });

  return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
    Awaited<ReturnType<typeof configRetrieve>>,
    TError,
    TData
  > & { queryKey: DataTag<QueryKey, TData, TError> };
};

export type ConfigRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof configRetrieve>>
>;
export type ConfigRetrieveQueryError = ErrorType<unknown>;

export function useConfigRetrieve<
  TData = Awaited<ReturnType<typeof configRetrieve>>,
  TError = ErrorType<unknown>,
>(
  options: {
    query: Partial<
      UseQueryOptions<Awaited<ReturnType<typeof configRetrieve>>, TError, TData>
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof configRetrieve>>,
          TError,
          Awaited<ReturnType<typeof configRetrieve>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useConfigRetrieve<
  TData = Awaited<ReturnType<typeof configRetrieve>>,
  TError = ErrorType<unknown>,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<Awaited<ReturnType<typeof configRetrieve>>, TError, TData>
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof configRetrieve>>,
          TError,
          Awaited<ReturnType<typeof configRetrieve>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useConfigRetrieve<
  TData = Awaited<ReturnType<typeof configRetrieve>>,
  TError = ErrorType<unknown>,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<Awaited<ReturnType<typeof configRetrieve>>, TError, TData>
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};

export function useConfigRetrieve<
  TData = Awaited<ReturnType<typeof configRetrieve>>,
  TError = ErrorType<unknown>,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<Awaited<ReturnType<typeof configRetrieve>>, TError, TData>
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getConfigRetrieveQueryOptions(options);

  const query = useQuery(queryOptions, queryClient) as UseQueryResult<
    TData,
    TError
  > & { queryKey: DataTag<QueryKey, TData, TError> };

  query.queryKey = queryOptions.queryKey;

  return query;
}
