/**
 * Generated by orval 🍺
 * Do not edit manually.
 * messages API
 * This is the messages API schema.
 * OpenAPI spec version: 1.0.0 (v1.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 {
  DriveUploadAttachmentRequest,
  PaginatedDriveItemResponse,
  PartialDriveItem,
  ThirdPartyDriveRetrieveParams,
} from ".././models";

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

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

/**
 * Search for files created by the current user.
 */
export type thirdPartyDriveRetrieveResponse200 = {
  data: PaginatedDriveItemResponse;
  status: 200;
};

export type thirdPartyDriveRetrieveResponseSuccess =
  thirdPartyDriveRetrieveResponse200 & {
    headers: Headers;
  };
export type thirdPartyDriveRetrieveResponse =
  thirdPartyDriveRetrieveResponseSuccess;

export const getThirdPartyDriveRetrieveUrl = (
  params: ThirdPartyDriveRetrieveParams,
) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? "null" : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

  return stringifiedParams.length > 0
    ? `/api/v1.0/third-party/drive/?${stringifiedParams}`
    : `/api/v1.0/third-party/drive/`;
};

export const thirdPartyDriveRetrieve = async (
  params: ThirdPartyDriveRetrieveParams,
  options?: RequestInit,
): Promise<thirdPartyDriveRetrieveResponse> => {
  return fetchAPI<thirdPartyDriveRetrieveResponse>(
    getThirdPartyDriveRetrieveUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getThirdPartyDriveRetrieveQueryKey = (
  params?: ThirdPartyDriveRetrieveParams,
) => {
  return [`/api/v1.0/third-party/drive/`, ...(params ? [params] : [])] as const;
};

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

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

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

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

export type ThirdPartyDriveRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof thirdPartyDriveRetrieve>>
>;
export type ThirdPartyDriveRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Create a new file in the main workspace.
 */
export type thirdPartyDriveCreateResponse201 = {
  data: PartialDriveItem;
  status: 201;
};

export type thirdPartyDriveCreateResponseSuccess =
  thirdPartyDriveCreateResponse201 & {
    headers: Headers;
  };
export type thirdPartyDriveCreateResponse =
  thirdPartyDriveCreateResponseSuccess;

export const getThirdPartyDriveCreateUrl = () => {
  return `/api/v1.0/third-party/drive/`;
};

export const thirdPartyDriveCreate = async (
  driveUploadAttachmentRequest: DriveUploadAttachmentRequest,
  options?: RequestInit,
): Promise<thirdPartyDriveCreateResponse> => {
  return fetchAPI<thirdPartyDriveCreateResponse>(
    getThirdPartyDriveCreateUrl(),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(driveUploadAttachmentRequest),
    },
  );
};

export const getThirdPartyDriveCreateMutationOptions = <
  TError = unknown,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof thirdPartyDriveCreate>>,
    TError,
    { data: DriveUploadAttachmentRequest },
    TContext
  >;
  request?: SecondParameter<typeof fetchAPI>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof thirdPartyDriveCreate>>,
  TError,
  { data: DriveUploadAttachmentRequest },
  TContext
> => {
  const mutationKey = ["thirdPartyDriveCreate"];
  const { mutation: mutationOptions, request: requestOptions } = options
    ? options.mutation &&
      "mutationKey" in options.mutation &&
      options.mutation.mutationKey
      ? options
      : { ...options, mutation: { ...options.mutation, mutationKey } }
    : { mutation: { mutationKey }, request: undefined };

  const mutationFn: MutationFunction<
    Awaited<ReturnType<typeof thirdPartyDriveCreate>>,
    { data: DriveUploadAttachmentRequest }
  > = (props) => {
    const { data } = props ?? {};

    return thirdPartyDriveCreate(data, requestOptions);
  };

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

export type ThirdPartyDriveCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof thirdPartyDriveCreate>>
>;
export type ThirdPartyDriveCreateMutationBody = DriveUploadAttachmentRequest;
export type ThirdPartyDriveCreateMutationError = unknown;

export const useThirdPartyDriveCreate = <TError = unknown, TContext = unknown>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof thirdPartyDriveCreate>>,
      TError,
      { data: DriveUploadAttachmentRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof thirdPartyDriveCreate>>,
  TError,
  { data: DriveUploadAttachmentRequest },
  TContext
> => {
  const mutationOptions = getThirdPartyDriveCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
