/**
 * Generated by orval v8.8.0 🍺
 * Do not edit manually.
 * OpenAPI spec version: 0.0.0
 */
import { useMutation, useQuery } from "@tanstack/react-query";
import type {
  DataTag,
  DefinedInitialDataOptions,
  DefinedUseQueryResult,
  MutationFunction,
  QueryClient,
  QueryFunction,
  QueryKey,
  UndefinedInitialDataOptions,
  UseMutationOptions,
  UseMutationResult,
  UseQueryOptions,
  UseQueryResult,
} from "@tanstack/react-query";

import type {
  ApiDownloaderDownloadCreateParams,
  ApiDownloaderDownloadFileCreateParams,
  ApiDownloaderDownloadFileRetrieveParams,
  ApiDownloaderDownloadRetrieveParams,
  DownloaderStats,
  ErrorResponse,
  TokenError,
  VideoInfoResponse,
} from "./models";

import { publicMutator } from "../../publicClient";

/**
 *
        Fetch detailed information about a video or playlist from supported platforms.

        **Supported platforms:** YouTube, TikTok, Vimeo, Twitter, Instagram, Facebook, Reddit, and many more.

        **Returns:**
        For single videos:
        - Video title, duration, and thumbnail
        - Available video qualities/resolutions
        - Available audio formats

        For playlists:
        - Array of videos with the same info structure as single videos
        - Each video includes title, duration, thumbnail, and available qualities

        **Usage:**
        ```
        GET /api/downloader/download/?url=https://youtube.com/watch?v=VIDEO_ID
        GET /api/downloader/download/?url=https://youtube.com/playlist?list=PLAYLIST_ID
        ```

 * @summary Get video info from URL
 */
export const apiDownloaderDownloadRetrieve = (
  params: ApiDownloaderDownloadRetrieveParams,
  signal?: AbortSignal,
) => {
  return publicMutator<VideoInfoResponse>({
    url: `/api/downloader/download/`,
    method: "GET",
    params,
    signal,
  });
};

export const getApiDownloaderDownloadRetrieveQueryKey = (
  params?: ApiDownloaderDownloadRetrieveParams,
) => {
  return [`/api/downloader/download/`, ...(params ? [params] : [])] as const;
};

export const getApiDownloaderDownloadRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
        TError,
        TData
      >
    >;
  },
) => {
  const { query: queryOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ?? getApiDownloaderDownloadRetrieveQueryKey(params);

  const queryFn: QueryFunction<
    Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>
  > = ({ signal }) => apiDownloaderDownloadRetrieve(params, signal);

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

export type ApiDownloaderDownloadRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>
>;
export type ApiDownloaderDownloadRetrieveQueryError = ErrorResponse;

export function useApiDownloaderDownloadRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadRetrieveParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiDownloaderDownloadRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiDownloaderDownloadRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get video info from URL
 */

export function useApiDownloaderDownloadRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getApiDownloaderDownloadRetrieveQueryOptions(
    params,
    options,
  );

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

  return { ...query, queryKey: queryOptions.queryKey };
}

/**
 * Serve a file using a signed token from WebSocket download. Token expires in 10 minutes.
 * @summary Download file via signed token
 */
export const apiDownloaderDownloadCreate = (
  params: ApiDownloaderDownloadCreateParams,
  signal?: AbortSignal,
) => {
  return publicMutator<Blob>({
    url: `/api/downloader/download/`,
    method: "POST",
    params,
    signal,
  });
};

export const getApiDownloaderDownloadCreateMutationOptions = <
  TError = TokenError,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
    TError,
    { params: ApiDownloaderDownloadCreateParams },
    TContext
  >;
}): UseMutationOptions<
  Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
  TError,
  { params: ApiDownloaderDownloadCreateParams },
  TContext
> => {
  const mutationKey = ["apiDownloaderDownloadCreate"];
  const { mutation: mutationOptions } = options
    ? options.mutation &&
      "mutationKey" in options.mutation &&
      options.mutation.mutationKey
      ? options
      : { ...options, mutation: { ...options.mutation, mutationKey } }
    : { mutation: { mutationKey } };

  const mutationFn: MutationFunction<
    Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
    { params: ApiDownloaderDownloadCreateParams }
  > = (props) => {
    const { params } = props ?? {};

    return apiDownloaderDownloadCreate(params);
  };

  return { mutationFn, ...mutationOptions };
};

export type ApiDownloaderDownloadCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>
>;

export type ApiDownloaderDownloadCreateMutationError = TokenError;

/**
 * @summary Download file via signed token
 */
export const useApiDownloaderDownloadCreate = <
  TError = TokenError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
      TError,
      { params: ApiDownloaderDownloadCreateParams },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
  TError,
  { params: ApiDownloaderDownloadCreateParams },
  TContext
> => {
  return useMutation(
    getApiDownloaderDownloadCreateMutationOptions(options),
    queryClient,
  );
};
/**
 *
        Fetch detailed information about a video or playlist from supported platforms.

        **Supported platforms:** YouTube, TikTok, Vimeo, Twitter, Instagram, Facebook, Reddit, and many more.

        **Returns:**
        For single videos:
        - Video title, duration, and thumbnail
        - Available video qualities/resolutions
        - Available audio formats

        For playlists:
        - Array of videos with the same info structure as single videos
        - Each video includes title, duration, thumbnail, and available qualities

        **Usage:**
        ```
        GET /api/downloader/download/?url=https://youtube.com/watch?v=VIDEO_ID
        GET /api/downloader/download/?url=https://youtube.com/playlist?list=PLAYLIST_ID
        ```

 * @summary Get video info from URL
 */
export const apiDownloaderDownloadFileRetrieve = (
  params: ApiDownloaderDownloadFileRetrieveParams,
  signal?: AbortSignal,
) => {
  return publicMutator<VideoInfoResponse>({
    url: `/api/downloader/download/file/`,
    method: "GET",
    params,
    signal,
  });
};

export const getApiDownloaderDownloadFileRetrieveQueryKey = (
  params?: ApiDownloaderDownloadFileRetrieveParams,
) => {
  return [
    `/api/downloader/download/file/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getApiDownloaderDownloadFileRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadFileRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
        TError,
        TData
      >
    >;
  },
) => {
  const { query: queryOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getApiDownloaderDownloadFileRetrieveQueryKey(params);

  const queryFn: QueryFunction<
    Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>
  > = ({ signal }) => apiDownloaderDownloadFileRetrieve(params, signal);

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

export type ApiDownloaderDownloadFileRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>
>;
export type ApiDownloaderDownloadFileRetrieveQueryError = ErrorResponse;

export function useApiDownloaderDownloadFileRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadFileRetrieveParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiDownloaderDownloadFileRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadFileRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiDownloaderDownloadFileRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadFileRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get video info from URL
 */

export function useApiDownloaderDownloadFileRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
  TError = ErrorResponse,
>(
  params: ApiDownloaderDownloadFileRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderDownloadFileRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getApiDownloaderDownloadFileRetrieveQueryOptions(
    params,
    options,
  );

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

  return { ...query, queryKey: queryOptions.queryKey };
}

/**
 * Serve a file using a signed token from WebSocket download. Token expires in 10 minutes.
 * @summary Download file via signed token
 */
export const apiDownloaderDownloadFileCreate = (
  params: ApiDownloaderDownloadFileCreateParams,
  signal?: AbortSignal,
) => {
  return publicMutator<Blob>({
    url: `/api/downloader/download/file/`,
    method: "POST",
    params,
    signal,
  });
};

export const getApiDownloaderDownloadFileCreateMutationOptions = <
  TError = TokenError,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof apiDownloaderDownloadFileCreate>>,
    TError,
    { params: ApiDownloaderDownloadFileCreateParams },
    TContext
  >;
}): UseMutationOptions<
  Awaited<ReturnType<typeof apiDownloaderDownloadFileCreate>>,
  TError,
  { params: ApiDownloaderDownloadFileCreateParams },
  TContext
> => {
  const mutationKey = ["apiDownloaderDownloadFileCreate"];
  const { mutation: mutationOptions } = options
    ? options.mutation &&
      "mutationKey" in options.mutation &&
      options.mutation.mutationKey
      ? options
      : { ...options, mutation: { ...options.mutation, mutationKey } }
    : { mutation: { mutationKey } };

  const mutationFn: MutationFunction<
    Awaited<ReturnType<typeof apiDownloaderDownloadFileCreate>>,
    { params: ApiDownloaderDownloadFileCreateParams }
  > = (props) => {
    const { params } = props ?? {};

    return apiDownloaderDownloadFileCreate(params);
  };

  return { mutationFn, ...mutationOptions };
};

export type ApiDownloaderDownloadFileCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof apiDownloaderDownloadFileCreate>>
>;

export type ApiDownloaderDownloadFileCreateMutationError = TokenError;

/**
 * @summary Download file via signed token
 */
export const useApiDownloaderDownloadFileCreate = <
  TError = TokenError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof apiDownloaderDownloadFileCreate>>,
      TError,
      { params: ApiDownloaderDownloadFileCreateParams },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof apiDownloaderDownloadFileCreate>>,
  TError,
  { params: ApiDownloaderDownloadFileCreateParams },
  TContext
> => {
  return useMutation(
    getApiDownloaderDownloadFileCreateMutationOptions(options),
    queryClient,
  );
};
/**
 * Vrací agregované statistiky z tabulky DownloaderRecord.
 * @summary Get aggregated downloader statistics
 */
export const apiDownloaderStatsRetrieve = (signal?: AbortSignal) => {
  return publicMutator<DownloaderStats>({
    url: `/api/downloader/stats/`,
    method: "GET",
    signal,
  });
};

export const getApiDownloaderStatsRetrieveQueryKey = () => {
  return [`/api/downloader/stats/`] as const;
};

export const getApiDownloaderStatsRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
  TError = unknown,
>(options?: {
  query?: Partial<
    UseQueryOptions<
      Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
      TError,
      TData
    >
  >;
}) => {
  const { query: queryOptions } = options ?? {};

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

  const queryFn: QueryFunction<
    Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>
  > = ({ signal }) => apiDownloaderStatsRetrieve(signal);

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

export type ApiDownloaderStatsRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>
>;
export type ApiDownloaderStatsRetrieveQueryError = unknown;

export function useApiDownloaderStatsRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
  TError = unknown,
>(
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiDownloaderStatsRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiDownloaderStatsRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get aggregated downloader statistics
 */

export function useApiDownloaderStatsRetrieve<
  TData = Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiDownloaderStatsRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getApiDownloaderStatsRetrieveQueryOptions(options);

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

  return { ...query, queryKey: queryOptions.queryKey };
}
