/**
 * 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 {
  PractitionerScreeningQuestionsResponse,
  PractitionerScreeningReportResponse,
  PractitionerShareReportResponse,
  PractitionerSubmitScreeningResponse,
  StartScreeningDto,
  StartScreeningResponseDto,
  SubmitScreeningDto,
} from "../generated.schemas";

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

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

/**
 * Creates a new screening in IN_PROGRESS status for the given client. If a PENDING screening already exists it is promoted to IN_PROGRESS. If an IN_PROGRESS screening already exists it is returned as-is. Use the returned `screening_uuid` to redirect the client to the assessment.
 * @summary Start an in-person screening for a client (no email sent)
 */
export const practitionerScreeningControllerStartScreeningV1 = (
  startScreeningDto: StartScreeningDto,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<StartScreeningResponseDto>(
    {
      url: `/v1/practitioner/screening/start`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: startScreeningDto,
      signal,
    },
    options,
  );
};

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

      return practitionerScreeningControllerStartScreeningV1(
        data,
        requestOptions,
      );
    };

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

export type PractitionerScreeningControllerStartScreeningV1MutationResult =
  NonNullable<
    Awaited<ReturnType<typeof practitionerScreeningControllerStartScreeningV1>>
  >;
export type PractitionerScreeningControllerStartScreeningV1MutationBody =
  StartScreeningDto;
export type PractitionerScreeningControllerStartScreeningV1MutationError = void;

/**
 * @summary Start an in-person screening for a client (no email sent)
 */
export const usePractitionerScreeningControllerStartScreeningV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<typeof practitionerScreeningControllerStartScreeningV1>
      >,
      TError,
      { data: StartScreeningDto },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof practitionerScreeningControllerStartScreeningV1>>,
  TError,
  { data: StartScreeningDto },
  TContext
> => {
  const mutationOptions =
    getPractitionerScreeningControllerStartScreeningV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Get all screening questions
 */
export const practitionerScreeningControllerGetQuestionsV1 = (
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<PractitionerScreeningQuestionsResponse>(
    { url: `/v1/practitioner/screening/questions`, method: "GET", signal },
    options,
  );
};

export const getPractitionerScreeningControllerGetQuestionsV1QueryKey = () => {
  return [`/v1/practitioner/screening/questions`] as const;
};

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

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

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

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

export type PractitionerScreeningControllerGetQuestionsV1QueryResult =
  NonNullable<
    Awaited<ReturnType<typeof practitionerScreeningControllerGetQuestionsV1>>
  >;
export type PractitionerScreeningControllerGetQuestionsV1QueryError = void;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * @summary Submit answers for a practitioner-created screening
 */
export const practitionerScreeningControllerSubmitAnswersV1 = (
  uuid: string,
  submitScreeningDto: SubmitScreeningDto,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<PractitionerSubmitScreeningResponse | void>(
    {
      url: `/v1/practitioner/screening/${uuid}/submit`,
      method: "POST",
      headers: { "Content-Type": "application/json" },
      data: submitScreeningDto,
      signal,
    },
    options,
  );
};

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

      return practitionerScreeningControllerSubmitAnswersV1(
        uuid,
        data,
        requestOptions,
      );
    };

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

export type PractitionerScreeningControllerSubmitAnswersV1MutationResult =
  NonNullable<
    Awaited<ReturnType<typeof practitionerScreeningControllerSubmitAnswersV1>>
  >;
export type PractitionerScreeningControllerSubmitAnswersV1MutationBody =
  SubmitScreeningDto;
export type PractitionerScreeningControllerSubmitAnswersV1MutationError = void;

/**
 * @summary Submit answers for a practitioner-created screening
 */
export const usePractitionerScreeningControllerSubmitAnswersV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<typeof practitionerScreeningControllerSubmitAnswersV1>
      >,
      TError,
      { uuid: string; data: SubmitScreeningDto },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof practitionerScreeningControllerSubmitAnswersV1>>,
  TError,
  { uuid: string; data: SubmitScreeningDto },
  TContext
> => {
  const mutationOptions =
    getPractitionerScreeningControllerSubmitAnswersV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Share a completed screening report with the client
 */
export const practitionerScreeningControllerShareReportV1 = (
  uuid: string,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<PractitionerShareReportResponse | void>(
    {
      url: `/v1/practitioner/screenings/${uuid}/share`,
      method: "POST",
      signal,
    },
    options,
  );
};

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

    return practitionerScreeningControllerShareReportV1(uuid, requestOptions);
  };

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

export type PractitionerScreeningControllerShareReportV1MutationResult =
  NonNullable<
    Awaited<ReturnType<typeof practitionerScreeningControllerShareReportV1>>
  >;

export type PractitionerScreeningControllerShareReportV1MutationError = void;

/**
 * @summary Share a completed screening report with the client
 */
export const usePractitionerScreeningControllerShareReportV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof practitionerScreeningControllerShareReportV1>>,
      TError,
      { uuid: string },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof practitionerScreeningControllerShareReportV1>>,
  TError,
  { uuid: string },
  TContext
> => {
  const mutationOptions =
    getPractitionerScreeningControllerShareReportV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Get screening report by UUID
 */
export const practitionerScreeningControllerGetReportV1 = (
  uuid: string,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<PractitionerScreeningReportResponse>(
    { url: `/v1/practitioner/screening/${uuid}/report`, method: "GET", signal },
    options,
  );
};

export const getPractitionerScreeningControllerGetReportV1QueryKey = (
  uuid?: string,
) => {
  return [`/v1/practitioner/screening/${uuid}/report`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ??
    getPractitionerScreeningControllerGetReportV1QueryKey(uuid);

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

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

export type PractitionerScreeningControllerGetReportV1QueryResult = NonNullable<
  Awaited<ReturnType<typeof practitionerScreeningControllerGetReportV1>>
>;
export type PractitionerScreeningControllerGetReportV1QueryError = void;

export function usePractitionerScreeningControllerGetReportV1<
  TData = Awaited<
    ReturnType<typeof practitionerScreeningControllerGetReportV1>
  >,
  TError = void,
>(
  uuid: string,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof practitionerScreeningControllerGetReportV1>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<
            ReturnType<typeof practitionerScreeningControllerGetReportV1>
          >,
          TError,
          Awaited<ReturnType<typeof practitionerScreeningControllerGetReportV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function usePractitionerScreeningControllerGetReportV1<
  TData = Awaited<
    ReturnType<typeof practitionerScreeningControllerGetReportV1>
  >,
  TError = void,
>(
  uuid: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof practitionerScreeningControllerGetReportV1>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<
            ReturnType<typeof practitionerScreeningControllerGetReportV1>
          >,
          TError,
          Awaited<ReturnType<typeof practitionerScreeningControllerGetReportV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function usePractitionerScreeningControllerGetReportV1<
  TData = Awaited<
    ReturnType<typeof practitionerScreeningControllerGetReportV1>
  >,
  TError = void,
>(
  uuid: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof practitionerScreeningControllerGetReportV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get screening report by UUID
 */

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}
