/**
 * 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 { UserWithAbilities } from ".././models";

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

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

/**
 * Return information on currently logged user
 */
export type usersMeRetrieveResponse200 = {
  data: UserWithAbilities;
  status: 200;
};

export type usersMeRetrieveResponseSuccess = usersMeRetrieveResponse200 & {
  headers: Headers;
};
export type usersMeRetrieveResponse = usersMeRetrieveResponseSuccess;

export const getUsersMeRetrieveUrl = () => {
  return `/api/v1.0/users/me/`;
};

export const usersMeRetrieve = async (
  options?: RequestInit,
): Promise<usersMeRetrieveResponse> => {
  return fetchAPI<usersMeRetrieveResponse>(getUsersMeRetrieveUrl(), {
    ...options,
    method: "GET",
  });
};

export const getUsersMeRetrieveQueryKey = () => {
  return [`/api/v1.0/users/me/`] as const;
};

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

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

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

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

export type UsersMeRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof usersMeRetrieve>>
>;
export type UsersMeRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}
