/**
 * Generated by orval v7.21.0 🍺
 * Do not edit manually.
 * MBHS
 * Multidimensional Behavioral Health Screen
 * OpenAPI spec version: 1.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 {
  PMNotificationActionResponse,
  PMNotificationControllerGetNotificationsV1Params,
  PMNotificationListResponse,
  PMUnreadCountResponse,
} from "../generated.schemas";

import { customInstance } from "../../../config/axios";

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

/**
 * @summary Get paginated list of notifications
 */
export const pMNotificationControllerGetNotificationsV1 = (
  params?: PMNotificationControllerGetNotificationsV1Params,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<PMNotificationListResponse>(
    {
      url: `/v1/practice-manager/notifications`,
      method: "GET",
      params,
      signal,
    },
    options,
  );
};

export const getPMNotificationControllerGetNotificationsV1QueryKey = (
  params?: PMNotificationControllerGetNotificationsV1Params,
) => {
  return [
    `/v1/practice-manager/notifications`,
    ...(params ? [params] : []),
  ] as const;
};

export const getPMNotificationControllerGetNotificationsV1QueryOptions = <
  TData = Awaited<
    ReturnType<typeof pMNotificationControllerGetNotificationsV1>
  >,
  TError = void,
>(
  params?: PMNotificationControllerGetNotificationsV1Params,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type PMNotificationControllerGetNotificationsV1QueryResult = NonNullable<
  Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>
>;
export type PMNotificationControllerGetNotificationsV1QueryError = void;

export function usePMNotificationControllerGetNotificationsV1<
  TData = Awaited<
    ReturnType<typeof pMNotificationControllerGetNotificationsV1>
  >,
  TError = void,
>(
  params: undefined | PMNotificationControllerGetNotificationsV1Params,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<
            ReturnType<typeof pMNotificationControllerGetNotificationsV1>
          >,
          TError,
          Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function usePMNotificationControllerGetNotificationsV1<
  TData = Awaited<
    ReturnType<typeof pMNotificationControllerGetNotificationsV1>
  >,
  TError = void,
>(
  params?: PMNotificationControllerGetNotificationsV1Params,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<
            ReturnType<typeof pMNotificationControllerGetNotificationsV1>
          >,
          TError,
          Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function usePMNotificationControllerGetNotificationsV1<
  TData = Awaited<
    ReturnType<typeof pMNotificationControllerGetNotificationsV1>
  >,
  TError = void,
>(
  params?: PMNotificationControllerGetNotificationsV1Params,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get paginated list of notifications
 */

export function usePMNotificationControllerGetNotificationsV1<
  TData = Awaited<
    ReturnType<typeof pMNotificationControllerGetNotificationsV1>
  >,
  TError = void,
>(
  params?: PMNotificationControllerGetNotificationsV1Params,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetNotificationsV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions =
    getPMNotificationControllerGetNotificationsV1QueryOptions(params, options);

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * @summary Get unread notification count
 */
export const pMNotificationControllerGetUnreadCountV1 = (
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<PMUnreadCountResponse>(
    {
      url: `/v1/practice-manager/notifications/unread-count`,
      method: "GET",
      signal,
    },
    options,
  );
};

export const getPMNotificationControllerGetUnreadCountV1QueryKey = () => {
  return [`/v1/practice-manager/notifications/unread-count`] as const;
};

export const getPMNotificationControllerGetUnreadCountV1QueryOptions = <
  TData = Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
  TError = void,
>(options?: {
  query?: Partial<
    UseQueryOptions<
      Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
      TError,
      TData
    >
  >;
  request?: SecondParameter<typeof customInstance>;
}) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type PMNotificationControllerGetUnreadCountV1QueryResult = NonNullable<
  Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>
>;
export type PMNotificationControllerGetUnreadCountV1QueryError = void;

export function usePMNotificationControllerGetUnreadCountV1<
  TData = Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
  TError = void,
>(
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
          TError,
          Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function usePMNotificationControllerGetUnreadCountV1<
  TData = Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
  TError = void,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
          TError,
          Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function usePMNotificationControllerGetUnreadCountV1<
  TData = Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
  TError = void,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get unread notification count
 */

export function usePMNotificationControllerGetUnreadCountV1<
  TData = Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
  TError = void,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof pMNotificationControllerGetUnreadCountV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions =
    getPMNotificationControllerGetUnreadCountV1QueryOptions(options);

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * @summary Mark a single notification as read
 */
export const pMNotificationControllerMarkAsReadV1 = (
  id: string,
  options?: SecondParameter<typeof customInstance>,
) => {
  return customInstance<PMNotificationActionResponse>(
    { url: `/v1/practice-manager/notifications/${id}/read`, method: "PATCH" },
    options,
  );
};

export const getPMNotificationControllerMarkAsReadV1MutationOptions = <
  TError = void,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof pMNotificationControllerMarkAsReadV1>>,
    TError,
    { id: string },
    TContext
  >;
  request?: SecondParameter<typeof customInstance>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof pMNotificationControllerMarkAsReadV1>>,
  TError,
  { id: string },
  TContext
> => {
  const mutationKey = ["pMNotificationControllerMarkAsReadV1"];
  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 pMNotificationControllerMarkAsReadV1>>,
    { id: string }
  > = (props) => {
    const { id } = props ?? {};

    return pMNotificationControllerMarkAsReadV1(id, requestOptions);
  };

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

export type PMNotificationControllerMarkAsReadV1MutationResult = NonNullable<
  Awaited<ReturnType<typeof pMNotificationControllerMarkAsReadV1>>
>;

export type PMNotificationControllerMarkAsReadV1MutationError = void;

/**
 * @summary Mark a single notification as read
 */
export const usePMNotificationControllerMarkAsReadV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof pMNotificationControllerMarkAsReadV1>>,
      TError,
      { id: string },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof pMNotificationControllerMarkAsReadV1>>,
  TError,
  { id: string },
  TContext
> => {
  const mutationOptions =
    getPMNotificationControllerMarkAsReadV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Mark all notifications as read
 */
export const pMNotificationControllerMarkAllAsReadV1 = (
  options?: SecondParameter<typeof customInstance>,
) => {
  return customInstance<PMNotificationActionResponse>(
    {
      url: `/v1/practice-manager/notifications/mark-all-read`,
      method: "PATCH",
    },
    options,
  );
};

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

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

export type PMNotificationControllerMarkAllAsReadV1MutationResult = NonNullable<
  Awaited<ReturnType<typeof pMNotificationControllerMarkAllAsReadV1>>
>;

export type PMNotificationControllerMarkAllAsReadV1MutationError = void;

/**
 * @summary Mark all notifications as read
 */
export const usePMNotificationControllerMarkAllAsReadV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof pMNotificationControllerMarkAllAsReadV1>>,
      TError,
      void,
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof pMNotificationControllerMarkAllAsReadV1>>,
  TError,
  void,
  TContext
> => {
  const mutationOptions =
    getPMNotificationControllerMarkAllAsReadV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Delete a notification
 */
export const pMNotificationControllerDeleteNotificationV1 = (
  id: string,
  options?: SecondParameter<typeof customInstance>,
) => {
  return customInstance<PMNotificationActionResponse>(
    { url: `/v1/practice-manager/notifications/${id}`, method: "DELETE" },
    options,
  );
};

export const getPMNotificationControllerDeleteNotificationV1MutationOptions = <
  TError = void,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof pMNotificationControllerDeleteNotificationV1>>,
    TError,
    { id: string },
    TContext
  >;
  request?: SecondParameter<typeof customInstance>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof pMNotificationControllerDeleteNotificationV1>>,
  TError,
  { id: string },
  TContext
> => {
  const mutationKey = ["pMNotificationControllerDeleteNotificationV1"];
  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 pMNotificationControllerDeleteNotificationV1>>,
    { id: string }
  > = (props) => {
    const { id } = props ?? {};

    return pMNotificationControllerDeleteNotificationV1(id, requestOptions);
  };

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

export type PMNotificationControllerDeleteNotificationV1MutationResult =
  NonNullable<
    Awaited<ReturnType<typeof pMNotificationControllerDeleteNotificationV1>>
  >;

export type PMNotificationControllerDeleteNotificationV1MutationError = void;

/**
 * @summary Delete a notification
 */
export const usePMNotificationControllerDeleteNotificationV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof pMNotificationControllerDeleteNotificationV1>>,
      TError,
      { id: string },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof pMNotificationControllerDeleteNotificationV1>>,
  TError,
  { id: string },
  TContext
> => {
  const mutationOptions =
    getPMNotificationControllerDeleteNotificationV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
