/**
 * 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 {
  ApiSchemaRetrieve200Four,
  ApiSchemaRetrieve200One,
  ApiSchemaRetrieve200Three,
  ApiSchemaRetrieve200Two,
  ApiSchemaRetrieveParams,
  OrderMini,
  OrderRead,
  PatchedOrderRead,
} from ".././models";

import { privateMutator } from "../../../privateClient";

// https://stackoverflow.com/questions/49579094/typescript-conditional-types-filter-out-readonly-properties-pick-only-requir/49579497#49579497
type IfEquals<X, Y, A = X, B = never> =
  (<T>() => T extends X ? 1 : 2) extends <T>() => T extends Y ? 1 : 2 ? A : B;

type WritableKeys<T> = {
  [P in keyof T]-?: IfEquals<
    { [Q in P]: T[P] },
    { -readonly [Q in P]: T[P] },
    P
  >;
}[keyof T];

type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
  k: infer I,
) => void
  ? I
  : never;
type DistributeReadOnlyOverUnions<T> = T extends any ? NonReadonly<T> : never;

type Writable<T> = Pick<T, WritableKeys<T>>;
type NonReadonly<T> = [T] extends [UnionToIntersection<T>]
  ? {
      [P in keyof Writable<T>]: T[P] extends object
        ? NonReadonly<NonNullable<T[P]>>
        : T[P];
    }
  : DistributeReadOnlyOverUnions<T>;

export const apiCommerceOrdersCarrierRetrieve = (
  id: number,
  signal?: AbortSignal,
) => {
  return privateMutator<OrderRead>({
    url: `/api/commerce/orders/${id}/carrier/`,
    method: "GET",
    signal,
  });
};

export const getApiCommerceOrdersCarrierRetrieveQueryKey = (id?: number) => {
  return [`/api/commerce/orders/${id}/carrier/`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ?? getApiCommerceOrdersCarrierRetrieveQueryKey(id);

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

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

export type ApiCommerceOrdersCarrierRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiCommerceOrdersCarrierRetrieve>>
>;
export type ApiCommerceOrdersCarrierRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

export const apiCommerceOrdersCarrierReadyToPickupPartialUpdate = (
  id: number,
  patchedOrderRead: NonReadonly<PatchedOrderRead>,
) => {
  return privateMutator<OrderRead>({
    url: `/api/commerce/orders/${id}/carrier/ready-to-pickup/`,
    method: "PATCH",
    headers: { "Content-Type": "application/json" },
    data: patchedOrderRead,
  });
};

export const getApiCommerceOrdersCarrierReadyToPickupPartialUpdateMutationOptions =
  <TError = unknown, TContext = unknown>(options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<typeof apiCommerceOrdersCarrierReadyToPickupPartialUpdate>
      >,
      TError,
      { id: number; data: NonReadonly<PatchedOrderRead> },
      TContext
    >;
  }): UseMutationOptions<
    Awaited<
      ReturnType<typeof apiCommerceOrdersCarrierReadyToPickupPartialUpdate>
    >,
    TError,
    { id: number; data: NonReadonly<PatchedOrderRead> },
    TContext
  > => {
    const mutationKey = ["apiCommerceOrdersCarrierReadyToPickupPartialUpdate"];
    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 apiCommerceOrdersCarrierReadyToPickupPartialUpdate>
      >,
      { id: number; data: NonReadonly<PatchedOrderRead> }
    > = (props) => {
      const { id, data } = props ?? {};

      return apiCommerceOrdersCarrierReadyToPickupPartialUpdate(id, data);
    };

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

export type ApiCommerceOrdersCarrierReadyToPickupPartialUpdateMutationResult =
  NonNullable<
    Awaited<
      ReturnType<typeof apiCommerceOrdersCarrierReadyToPickupPartialUpdate>
    >
  >;
export type ApiCommerceOrdersCarrierReadyToPickupPartialUpdateMutationBody =
  NonReadonly<PatchedOrderRead>;
export type ApiCommerceOrdersCarrierReadyToPickupPartialUpdateMutationError =
  unknown;

export const useApiCommerceOrdersCarrierReadyToPickupPartialUpdate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<typeof apiCommerceOrdersCarrierReadyToPickupPartialUpdate>
      >,
      TError,
      { id: number; data: NonReadonly<PatchedOrderRead> },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<
    ReturnType<typeof apiCommerceOrdersCarrierReadyToPickupPartialUpdate>
  >,
  TError,
  { id: number; data: NonReadonly<PatchedOrderRead> },
  TContext
> => {
  const mutationOptions =
    getApiCommerceOrdersCarrierReadyToPickupPartialUpdateMutationOptions(
      options,
    );

  return useMutation(mutationOptions, queryClient);
};
export const apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate = (
  id: number,
  patchedOrderRead: NonReadonly<PatchedOrderRead>,
) => {
  return privateMutator<OrderRead>({
    url: `/api/commerce/orders/${id}/carrier/start-ordering-shipping/`,
    method: "PATCH",
    headers: { "Content-Type": "application/json" },
    data: patchedOrderRead,
  });
};

export const getApiCommerceOrdersCarrierStartOrderingShippingPartialUpdateMutationOptions =
  <TError = unknown, TContext = unknown>(options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<
          typeof apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate
        >
      >,
      TError,
      { id: number; data: NonReadonly<PatchedOrderRead> },
      TContext
    >;
  }): UseMutationOptions<
    Awaited<
      ReturnType<
        typeof apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate
      >
    >,
    TError,
    { id: number; data: NonReadonly<PatchedOrderRead> },
    TContext
  > => {
    const mutationKey = [
      "apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate",
    ];
    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 apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate
        >
      >,
      { id: number; data: NonReadonly<PatchedOrderRead> }
    > = (props) => {
      const { id, data } = props ?? {};

      return apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate(
        id,
        data,
      );
    };

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

export type ApiCommerceOrdersCarrierStartOrderingShippingPartialUpdateMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate
      >
    >
  >;
export type ApiCommerceOrdersCarrierStartOrderingShippingPartialUpdateMutationBody =
  NonReadonly<PatchedOrderRead>;
export type ApiCommerceOrdersCarrierStartOrderingShippingPartialUpdateMutationError =
  unknown;

export const useApiCommerceOrdersCarrierStartOrderingShippingPartialUpdate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<
          typeof apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate
        >
      >,
      TError,
      { id: number; data: NonReadonly<PatchedOrderRead> },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<
    ReturnType<
      typeof apiCommerceOrdersCarrierStartOrderingShippingPartialUpdate
    >
  >,
  TError,
  { id: number; data: NonReadonly<PatchedOrderRead> },
  TContext
> => {
  const mutationOptions =
    getApiCommerceOrdersCarrierStartOrderingShippingPartialUpdateMutationOptions(
      options,
    );

  return useMutation(mutationOptions, queryClient);
};
export const apiCommerceOrdersItemsRetrieve = (
  id: number,
  signal?: AbortSignal,
) => {
  return privateMutator<OrderRead>({
    url: `/api/commerce/orders/${id}/items/`,
    method: "GET",
    signal,
  });
};

export const getApiCommerceOrdersItemsRetrieveQueryKey = (id?: number) => {
  return [`/api/commerce/orders/${id}/items/`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ?? getApiCommerceOrdersItemsRetrieveQueryKey(id);

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

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

export type ApiCommerceOrdersItemsRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiCommerceOrdersItemsRetrieve>>
>;
export type ApiCommerceOrdersItemsRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

export const apiCommerceOrdersPaymentRetrieve = (
  id: number,
  signal?: AbortSignal,
) => {
  return privateMutator<OrderRead>({
    url: `/api/commerce/orders/${id}/payment/`,
    method: "GET",
    signal,
  });
};

export const getApiCommerceOrdersPaymentRetrieveQueryKey = (id?: number) => {
  return [`/api/commerce/orders/${id}/payment/`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ?? getApiCommerceOrdersPaymentRetrieveQueryKey(id);

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

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

export type ApiCommerceOrdersPaymentRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiCommerceOrdersPaymentRetrieve>>
>;
export type ApiCommerceOrdersPaymentRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

export const apiCommerceOrdersDetailRetrieve = (signal?: AbortSignal) => {
  return privateMutator<OrderMini>({
    url: `/api/commerce/orders/detail/`,
    method: "GET",
    signal,
  });
};

export const getApiCommerceOrdersDetailRetrieveQueryKey = () => {
  return [`/api/commerce/orders/detail/`] as const;
};

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

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

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

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

export type ApiCommerceOrdersDetailRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiCommerceOrdersDetailRetrieve>>
>;
export type ApiCommerceOrdersDetailRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Public endpoint to create and fetch refund objects.

POST: Create a refund given email and invoice_number or order_id.
          Returns JSON with refund info, order items, and a base64 PDF payload.
GET:  Return a refund object by id (query param `id`).
 */
export const apiCommerceRefundsPublicRetrieve = (signal?: AbortSignal) => {
  return privateMutator<void>({
    url: `/api/commerce/refunds/public/`,
    method: "GET",
    signal,
  });
};

export const getApiCommerceRefundsPublicRetrieveQueryKey = () => {
  return [`/api/commerce/refunds/public/`] as const;
};

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

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

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

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

export type ApiCommerceRefundsPublicRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiCommerceRefundsPublicRetrieve>>
>;
export type ApiCommerceRefundsPublicRetrieveQueryError = unknown;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Public endpoint to create and fetch refund objects.

POST: Create a refund given email and invoice_number or order_id.
          Returns JSON with refund info, order items, and a base64 PDF payload.
GET:  Return a refund object by id (query param `id`).
 */
export const apiCommerceRefundsPublicCreate = (signal?: AbortSignal) => {
  return privateMutator<void>({
    url: `/api/commerce/refunds/public/`,
    method: "POST",
    signal,
  });
};

export const getApiCommerceRefundsPublicCreateMutationOptions = <
  TError = unknown,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof apiCommerceRefundsPublicCreate>>,
    TError,
    void,
    TContext
  >;
}): UseMutationOptions<
  Awaited<ReturnType<typeof apiCommerceRefundsPublicCreate>>,
  TError,
  void,
  TContext
> => {
  const mutationKey = ["apiCommerceRefundsPublicCreate"];
  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 apiCommerceRefundsPublicCreate>>,
    void
  > = () => {
    return apiCommerceRefundsPublicCreate();
  };

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

export type ApiCommerceRefundsPublicCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof apiCommerceRefundsPublicCreate>>
>;

export type ApiCommerceRefundsPublicCreateMutationError = unknown;

export const useApiCommerceRefundsPublicCreate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof apiCommerceRefundsPublicCreate>>,
      TError,
      void,
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof apiCommerceRefundsPublicCreate>>,
  TError,
  void,
  TContext
> => {
  const mutationOptions =
    getApiCommerceRefundsPublicCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * OpenApi3 schema for this API. Format can be selected via content negotiation.

- YAML: application/vnd.oai.openapi
- JSON: application/vnd.oai.openapi+json
 */
export const apiSchemaRetrieve = (
  params?: ApiSchemaRetrieveParams,
  signal?: AbortSignal,
) => {
  return privateMutator<
    | ApiSchemaRetrieve200One
    | ApiSchemaRetrieve200Two
    | ApiSchemaRetrieve200Three
    | ApiSchemaRetrieve200Four
  >({ url: `/api/schema/`, method: "GET", params, signal });
};

export const getApiSchemaRetrieveQueryKey = (
  params?: ApiSchemaRetrieveParams,
) => {
  return [`/api/schema/`, ...(params ? [params] : [])] as const;
};

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

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

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

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

export type ApiSchemaRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiSchemaRetrieve>>
>;
export type ApiSchemaRetrieveQueryError = unknown;

export function useApiSchemaRetrieve<
  TData = Awaited<ReturnType<typeof apiSchemaRetrieve>>,
  TError = unknown,
>(
  params: undefined | ApiSchemaRetrieveParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiSchemaRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiSchemaRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiSchemaRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiSchemaRetrieve<
  TData = Awaited<ReturnType<typeof apiSchemaRetrieve>>,
  TError = unknown,
>(
  params?: ApiSchemaRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiSchemaRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiSchemaRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiSchemaRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiSchemaRetrieve<
  TData = Awaited<ReturnType<typeof apiSchemaRetrieve>>,
  TError = unknown,
>(
  params?: ApiSchemaRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiSchemaRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}
