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

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

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

/**
 * 
    Get the status of an async task.

    This endpoint returns the current status of a task identified by its ID.
    
 */
export type tasksRetrieveResponse200 = {
  data: TaskStatusResponse;
  status: 200;
};

export type tasksRetrieveResponseSuccess = tasksRetrieveResponse200 & {
  headers: Headers;
};
export type tasksRetrieveResponse = tasksRetrieveResponseSuccess;

export const getTasksRetrieveUrl = (taskId: string) => {
  return `/api/v1.0/tasks/${taskId}/`;
};

export const tasksRetrieve = async (
  taskId: string,
  options?: RequestInit,
): Promise<tasksRetrieveResponse> => {
  return fetchAPI<tasksRetrieveResponse>(getTasksRetrieveUrl(taskId), {
    ...options,
    method: "GET",
  });
};

export const getTasksRetrieveQueryKey = (taskId?: string) => {
  return [`/api/v1.0/tasks/${taskId}/`] as const;
};

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

  const queryKey = queryOptions?.queryKey ?? getTasksRetrieveQueryKey(taskId);

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

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

export type TasksRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof tasksRetrieve>>
>;
export type TasksRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}
