/**
 * 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 {
  ApiNotificationsListParams,
  ApiNotificationsReadAllCreate200,
  ApiNotificationsUnreadCountRetrieve200,
  Notification,
  PaginatedNotificationList,
} 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 apiNotificationsList = (
  params?: ApiNotificationsListParams,
  signal?: AbortSignal,
) => {
  return privateMutator<PaginatedNotificationList>({
    url: `/api/notifications/`,
    method: "GET",
    params,
    signal,
  });
};

export const getApiNotificationsListQueryKey = (
  params?: ApiNotificationsListParams,
) => {
  return [`/api/notifications/`, ...(params ? [params] : [])] as const;
};

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

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

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

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

export type ApiNotificationsListQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiNotificationsList>>
>;
export type ApiNotificationsListQueryError = unknown;

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

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

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

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

export const apiNotificationsRetrieve = (id: string, signal?: AbortSignal) => {
  return privateMutator<Notification>({
    url: `/api/notifications/${id}/`,
    method: "GET",
    signal,
  });
};

export const getApiNotificationsRetrieveQueryKey = (id: string) => {
  return [`/api/notifications/${id}/`] as const;
};

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

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

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

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

export type ApiNotificationsRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiNotificationsRetrieve>>
>;
export type ApiNotificationsRetrieveQueryError = unknown;

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

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

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

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

/**
 * @summary Mark a single notification as read
 */
export const apiNotificationsReadCreate = (
  id: string,
  notification: NonReadonly<Notification>,
  signal?: AbortSignal,
) => {
  return privateMutator<Notification>({
    url: `/api/notifications/${id}/read/`,
    method: "POST",
    headers: { "Content-Type": "application/json" },
    data: notification,
    signal,
  });
};

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

    return apiNotificationsReadCreate(id, data);
  };

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

export type ApiNotificationsReadCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof apiNotificationsReadCreate>>
>;
export type ApiNotificationsReadCreateMutationBody = NonReadonly<Notification>;
export type ApiNotificationsReadCreateMutationError = unknown;

/**
 * @summary Mark a single notification as read
 */
export const useApiNotificationsReadCreate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof apiNotificationsReadCreate>>,
      TError,
      { id: string; data: NonReadonly<Notification> },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof apiNotificationsReadCreate>>,
  TError,
  { id: string; data: NonReadonly<Notification> },
  TContext
> => {
  return useMutation(
    getApiNotificationsReadCreateMutationOptions(options),
    queryClient,
  );
};
/**
 * @summary Mark all notifications as read
 */
export const apiNotificationsReadAllCreate = (
  notification: NonReadonly<Notification>,
  signal?: AbortSignal,
) => {
  return privateMutator<ApiNotificationsReadAllCreate200>({
    url: `/api/notifications/read-all/`,
    method: "POST",
    headers: { "Content-Type": "application/json" },
    data: notification,
    signal,
  });
};

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

    return apiNotificationsReadAllCreate(data);
  };

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

export type ApiNotificationsReadAllCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof apiNotificationsReadAllCreate>>
>;
export type ApiNotificationsReadAllCreateMutationBody =
  NonReadonly<Notification>;
export type ApiNotificationsReadAllCreateMutationError = unknown;

/**
 * @summary Mark all notifications as read
 */
export const useApiNotificationsReadAllCreate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof apiNotificationsReadAllCreate>>,
      TError,
      { data: NonReadonly<Notification> },
      TContext
    >;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof apiNotificationsReadAllCreate>>,
  TError,
  { data: NonReadonly<Notification> },
  TContext
> => {
  return useMutation(
    getApiNotificationsReadAllCreateMutationOptions(options),
    queryClient,
  );
};
/**
 * @summary Unread notification count
 */
export const apiNotificationsUnreadCountRetrieve = (signal?: AbortSignal) => {
  return privateMutator<ApiNotificationsUnreadCountRetrieve200>({
    url: `/api/notifications/unread-count/`,
    method: "GET",
    signal,
  });
};

export const getApiNotificationsUnreadCountRetrieveQueryKey = () => {
  return [`/api/notifications/unread-count/`] as const;
};

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

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

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

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

export type ApiNotificationsUnreadCountRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>
>;
export type ApiNotificationsUnreadCountRetrieveQueryError = unknown;

export function useApiNotificationsUnreadCountRetrieve<
  TData = Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
  TError = unknown,
>(
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiNotificationsUnreadCountRetrieve<
  TData = Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
          TError,
          Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>
        >,
        "initialData"
      >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useApiNotificationsUnreadCountRetrieve<
  TData = Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof apiNotificationsUnreadCountRetrieve>>,
        TError,
        TData
      >
    >;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Unread notification count
 */

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

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

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