/**
 * 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 {
  InviteTherapistDto,
  InviteTherapistResponse,
  RemoveTherapistResponse,
  TherapistListResponse,
  TherapistsControllerListTherapistsV1Params,
  ToggleTherapistStatusResponse,
  UpdateTherapistDto,
  UpdateTherapistResponse,
} from "../generated.schemas";

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

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

/**
 * @summary List team therapists
 */
export const therapistsControllerListTherapistsV1 = (
  params?: TherapistsControllerListTherapistsV1Params,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  return customInstance<TherapistListResponse>(
    { url: `/v1/practice-manager/therapists`, method: "GET", params, signal },
    options,
  );
};

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

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

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

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

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

export type TherapistsControllerListTherapistsV1QueryResult = NonNullable<
  Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>
>;
export type TherapistsControllerListTherapistsV1QueryError = void;

export function useTherapistsControllerListTherapistsV1<
  TData = Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
  TError = void,
>(
  params: undefined | TherapistsControllerListTherapistsV1Params,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
          TError,
          Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useTherapistsControllerListTherapistsV1<
  TData = Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
  TError = void,
>(
  params?: TherapistsControllerListTherapistsV1Params,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
          TError,
          Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useTherapistsControllerListTherapistsV1<
  TData = Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
  TError = void,
>(
  params?: TherapistsControllerListTherapistsV1Params,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof therapistsControllerListTherapistsV1>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary List team therapists
 */

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * @summary Invite a new therapist to the team
 */
export const therapistsControllerInviteTherapistV1 = (
  inviteTherapistDto: InviteTherapistDto,
  options?: SecondParameter<typeof customInstance>,
  signal?: AbortSignal,
) => {
  const formUrlEncoded = new URLSearchParams();
  formUrlEncoded.append(`name`, inviteTherapistDto.name);
  formUrlEncoded.append(`email`, inviteTherapistDto.email);
  if (inviteTherapistDto.phone !== undefined) {
    formUrlEncoded.append(`phone`, inviteTherapistDto.phone);
  }

  return customInstance<InviteTherapistResponse>(
    {
      url: `/v1/practice-manager/therapists/invite`,
      method: "POST",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      data: formUrlEncoded,
      signal,
    },
    options,
  );
};

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

    return therapistsControllerInviteTherapistV1(data, requestOptions);
  };

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

export type TherapistsControllerInviteTherapistV1MutationResult = NonNullable<
  Awaited<ReturnType<typeof therapistsControllerInviteTherapistV1>>
>;
export type TherapistsControllerInviteTherapistV1MutationBody =
  InviteTherapistDto;
export type TherapistsControllerInviteTherapistV1MutationError = void;

/**
 * @summary Invite a new therapist to the team
 */
export const useTherapistsControllerInviteTherapistV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof therapistsControllerInviteTherapistV1>>,
      TError,
      { data: InviteTherapistDto },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof therapistsControllerInviteTherapistV1>>,
  TError,
  { data: InviteTherapistDto },
  TContext
> => {
  const mutationOptions =
    getTherapistsControllerInviteTherapistV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Update therapist details
 */
export const therapistsControllerUpdateTherapistV1 = (
  uuid: string,
  updateTherapistDto: UpdateTherapistDto,
  options?: SecondParameter<typeof customInstance>,
) => {
  const formUrlEncoded = new URLSearchParams();
  if (updateTherapistDto.name !== undefined) {
    formUrlEncoded.append(`name`, updateTherapistDto.name);
  }
  if (updateTherapistDto.email !== undefined) {
    formUrlEncoded.append(`email`, updateTherapistDto.email);
  }
  if (updateTherapistDto.phone !== undefined) {
    formUrlEncoded.append(`phone`, updateTherapistDto.phone);
  }

  return customInstance<UpdateTherapistResponse>(
    {
      url: `/v1/practice-manager/therapists/${uuid}`,
      method: "PUT",
      headers: { "Content-Type": "application/x-www-form-urlencoded" },
      data: formUrlEncoded,
    },
    options,
  );
};

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

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

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

export type TherapistsControllerUpdateTherapistV1MutationResult = NonNullable<
  Awaited<ReturnType<typeof therapistsControllerUpdateTherapistV1>>
>;
export type TherapistsControllerUpdateTherapistV1MutationBody =
  UpdateTherapistDto;
export type TherapistsControllerUpdateTherapistV1MutationError = void;

/**
 * @summary Update therapist details
 */
export const useTherapistsControllerUpdateTherapistV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof therapistsControllerUpdateTherapistV1>>,
      TError,
      { uuid: string; data: UpdateTherapistDto },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof therapistsControllerUpdateTherapistV1>>,
  TError,
  { uuid: string; data: UpdateTherapistDto },
  TContext
> => {
  const mutationOptions =
    getTherapistsControllerUpdateTherapistV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Remove therapist from team
 */
export const therapistsControllerRemoveTherapistV1 = (
  uuid: string,
  options?: SecondParameter<typeof customInstance>,
) => {
  return customInstance<RemoveTherapistResponse>(
    { url: `/v1/practice-manager/therapists/${uuid}`, method: "DELETE" },
    options,
  );
};

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

    return therapistsControllerRemoveTherapistV1(uuid, requestOptions);
  };

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

export type TherapistsControllerRemoveTherapistV1MutationResult = NonNullable<
  Awaited<ReturnType<typeof therapistsControllerRemoveTherapistV1>>
>;

export type TherapistsControllerRemoveTherapistV1MutationError = void;

/**
 * @summary Remove therapist from team
 */
export const useTherapistsControllerRemoveTherapistV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof therapistsControllerRemoveTherapistV1>>,
      TError,
      { uuid: string },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof therapistsControllerRemoveTherapistV1>>,
  TError,
  { uuid: string },
  TContext
> => {
  const mutationOptions =
    getTherapistsControllerRemoveTherapistV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * @summary Toggle therapist active/inactive status
 */
export const therapistsControllerToggleStatusV1 = (
  uuid: string,
  options?: SecondParameter<typeof customInstance>,
) => {
  return customInstance<ToggleTherapistStatusResponse>(
    { url: `/v1/practice-manager/therapists/${uuid}/status`, method: "PATCH" },
    options,
  );
};

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

    return therapistsControllerToggleStatusV1(uuid, requestOptions);
  };

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

export type TherapistsControllerToggleStatusV1MutationResult = NonNullable<
  Awaited<ReturnType<typeof therapistsControllerToggleStatusV1>>
>;

export type TherapistsControllerToggleStatusV1MutationError = void;

/**
 * @summary Toggle therapist active/inactive status
 */
export const useTherapistsControllerToggleStatusV1 = <
  TError = void,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof therapistsControllerToggleStatusV1>>,
      TError,
      { uuid: string },
      TContext
    >;
    request?: SecondParameter<typeof customInstance>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof therapistsControllerToggleStatusV1>>,
  TError,
  { uuid: string },
  TContext
> => {
  const mutationOptions =
    getTherapistsControllerToggleStatusV1MutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
