/**
 * Generated by orval v7.17.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 {
  ApiDownloaderDownloadRetrieveParams,
  DownloadErrorResponse,
  DownloadRequest,
  DownloaderStats,
  ErrorResponse,
  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> };

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * 
        Download video/playlist with optional quality constraints and container format conversion.
        
        **For Playlists:**
        - Returns a ZIP file containing all selected videos
        - Use `selected_videos` to specify which videos to download (e.g., [1,3,5] or [1,2,3,4,5])
        - If `selected_videos` is not provided, all videos in the playlist will be downloaded
        
        **Quality Parameters (optional):**
        - If not specified, yt-dlp will automatically select the best available quality.
        - `video_quality`: Maximum video height in pixels (e.g., 1080, 720, 480).
        - `audio_quality`: Maximum audio bitrate in kbps (e.g., 320, 192, 128).
        
        **Format/Extension:**
        - Any format supported by ffmpeg (mp4, mkv, webm, avi, mov, flv, m4a, mp3, etc.).
        - Defaults to 'mp4' if not specified.
        - The conversion is handled automatically by ffmpeg in the background.
        
        **Advanced Options:**
        - `subtitles`: Download subtitles (language codes like 'en,cs' or 'all')
        - `embed_subtitles`: Embed subtitles into video file
        - `embed_thumbnail`: Embed thumbnail as cover art
        - `extract_audio`: Extract audio only (ignores video quality)
        - `cookies`: Browser cookies for age-restricted content (Netscape format)
        
 * @summary Download video or playlist from URL
 */
export const apiDownloaderDownloadCreate = (
  downloadRequest: DownloadRequest,
  signal?: AbortSignal,
) => {
  return publicMutator<Blob>({
    url: `/api/downloader/download/`,
    method: "POST",
    headers: { "Content-Type": "application/json" },
    data: downloadRequest,
    responseType: "blob",
    signal,
  });
};

export const getApiDownloaderDownloadCreateMutationOptions = <
  TError = DownloadErrorResponse,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
    TError,
    { data: DownloadRequest },
    TContext
  >;
}): UseMutationOptions<
  Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
  TError,
  { data: DownloadRequest },
  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>>,
    { data: DownloadRequest }
  > = (props) => {
    const { data } = props ?? {};

    return apiDownloaderDownloadCreate(data);
  };

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

export type ApiDownloaderDownloadCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>
>;
export type ApiDownloaderDownloadCreateMutationBody = DownloadRequest;
export type ApiDownloaderDownloadCreateMutationError = DownloadErrorResponse;

/**
 * @summary Download video or playlist from URL
 */
export const useApiDownloaderDownloadCreate = <
  TError = DownloadErrorResponse,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
      TError,
      { data: DownloadRequest },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof apiDownloaderDownloadCreate>>,
  TError,
  { data: DownloadRequest },
  TContext
> => {
  const mutationOptions =
    getApiDownloaderDownloadCreateMutationOptions(options);

  return useMutation(mutationOptions, 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> };

  query.queryKey = queryOptions.queryKey;

  return query;
}
