/**
 * Generated by orval 🍺
 * Do not edit manually.
 * messages API
 * This is the messages API schema.
 * OpenAPI spec version: 1.0.0 (v1.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 {
  MailboxAccessRead,
  MailboxAccessWrite,
  MailboxAccessWriteRequest,
  MailboxesAccessesListParams,
  PaginatedMailboxAccessReadList,
  PatchedMailboxAccessWriteRequest,
} from ".././models";

import { fetchAPI } from "../../fetch-api";

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

/**
 * ViewSet for managing MailboxAccess records for a specific Mailbox.
The mailbox_id is expected as part of the URL.
Access is allowed if the user has MailboxAccess (ADMIN role)
to the target Mailbox itself, or is a domain admin of the mailbox's domain.
 */
export type mailboxesAccessesListResponse200 = {
  data: PaginatedMailboxAccessReadList;
  status: 200;
};

export type mailboxesAccessesListResponseSuccess =
  mailboxesAccessesListResponse200 & {
    headers: Headers;
  };
export type mailboxesAccessesListResponse =
  mailboxesAccessesListResponseSuccess;

export const getMailboxesAccessesListUrl = (
  mailboxId: string,
  params?: MailboxesAccessesListParams,
) => {
  const normalizedParams = new URLSearchParams();

  Object.entries(params || {}).forEach(([key, value]) => {
    if (value !== undefined) {
      normalizedParams.append(key, value === null ? "null" : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

  return stringifiedParams.length > 0
    ? `/api/v1.0/mailboxes/${mailboxId}/accesses/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${mailboxId}/accesses/`;
};

export const mailboxesAccessesList = async (
  mailboxId: string,
  params?: MailboxesAccessesListParams,
  options?: RequestInit,
): Promise<mailboxesAccessesListResponse> => {
  return fetchAPI<mailboxesAccessesListResponse>(
    getMailboxesAccessesListUrl(mailboxId, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesAccessesListQueryKey = (
  mailboxId?: string,
  params?: MailboxesAccessesListParams,
) => {
  return [
    `/api/v1.0/mailboxes/${mailboxId}/accesses/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getMailboxesAccessesListQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesAccessesList>>,
  TError = unknown,
>(
  mailboxId: string,
  params?: MailboxesAccessesListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getMailboxesAccessesListQueryKey(mailboxId, params);

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

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

export type MailboxesAccessesListQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesAccessesList>>
>;
export type MailboxesAccessesListQueryError = unknown;

export function useMailboxesAccessesList<
  TData = Awaited<ReturnType<typeof mailboxesAccessesList>>,
  TError = unknown,
>(
  mailboxId: string,
  params: undefined | MailboxesAccessesListParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesList>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof mailboxesAccessesList>>,
          TError,
          Awaited<ReturnType<typeof mailboxesAccessesList>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useMailboxesAccessesList<
  TData = Awaited<ReturnType<typeof mailboxesAccessesList>>,
  TError = unknown,
>(
  mailboxId: string,
  params?: MailboxesAccessesListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesList>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof mailboxesAccessesList>>,
          TError,
          Awaited<ReturnType<typeof mailboxesAccessesList>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useMailboxesAccessesList<
  TData = Awaited<ReturnType<typeof mailboxesAccessesList>>,
  TError = unknown,
>(
  mailboxId: string,
  params?: MailboxesAccessesListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};

export function useMailboxesAccessesList<
  TData = Awaited<ReturnType<typeof mailboxesAccessesList>>,
  TError = unknown,
>(
  mailboxId: string,
  params?: MailboxesAccessesListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesAccessesListQueryOptions(
    mailboxId,
    params,
    options,
  );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * ViewSet for managing MailboxAccess records for a specific Mailbox.
The mailbox_id is expected as part of the URL.
Access is allowed if the user has MailboxAccess (ADMIN role)
to the target Mailbox itself, or is a domain admin of the mailbox's domain.
 */
export type mailboxesAccessesCreateResponse201 = {
  data: MailboxAccessWrite;
  status: 201;
};

export type mailboxesAccessesCreateResponseSuccess =
  mailboxesAccessesCreateResponse201 & {
    headers: Headers;
  };
export type mailboxesAccessesCreateResponse =
  mailboxesAccessesCreateResponseSuccess;

export const getMailboxesAccessesCreateUrl = (mailboxId: string) => {
  return `/api/v1.0/mailboxes/${mailboxId}/accesses/`;
};

export const mailboxesAccessesCreate = async (
  mailboxId: string,
  mailboxAccessWriteRequest: MailboxAccessWriteRequest,
  options?: RequestInit,
): Promise<mailboxesAccessesCreateResponse> => {
  return fetchAPI<mailboxesAccessesCreateResponse>(
    getMailboxesAccessesCreateUrl(mailboxId),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(mailboxAccessWriteRequest),
    },
  );
};

export const getMailboxesAccessesCreateMutationOptions = <
  TError = unknown,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof mailboxesAccessesCreate>>,
    TError,
    { mailboxId: string; data: MailboxAccessWriteRequest },
    TContext
  >;
  request?: SecondParameter<typeof fetchAPI>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof mailboxesAccessesCreate>>,
  TError,
  { mailboxId: string; data: MailboxAccessWriteRequest },
  TContext
> => {
  const mutationKey = ["mailboxesAccessesCreate"];
  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 mailboxesAccessesCreate>>,
    { mailboxId: string; data: MailboxAccessWriteRequest }
  > = (props) => {
    const { mailboxId, data } = props ?? {};

    return mailboxesAccessesCreate(mailboxId, data, requestOptions);
  };

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

export type MailboxesAccessesCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesAccessesCreate>>
>;
export type MailboxesAccessesCreateMutationBody = MailboxAccessWriteRequest;
export type MailboxesAccessesCreateMutationError = unknown;

export const useMailboxesAccessesCreate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesAccessesCreate>>,
      TError,
      { mailboxId: string; data: MailboxAccessWriteRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesAccessesCreate>>,
  TError,
  { mailboxId: string; data: MailboxAccessWriteRequest },
  TContext
> => {
  const mutationOptions = getMailboxesAccessesCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * ViewSet for managing MailboxAccess records for a specific Mailbox.
The mailbox_id is expected as part of the URL.
Access is allowed if the user has MailboxAccess (ADMIN role)
to the target Mailbox itself, or is a domain admin of the mailbox's domain.
 */
export type mailboxesAccessesRetrieveResponse200 = {
  data: MailboxAccessRead;
  status: 200;
};

export type mailboxesAccessesRetrieveResponseSuccess =
  mailboxesAccessesRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesAccessesRetrieveResponse =
  mailboxesAccessesRetrieveResponseSuccess;

export const getMailboxesAccessesRetrieveUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/accesses/${id}/`;
};

export const mailboxesAccessesRetrieve = async (
  mailboxId: string,
  id: string,
  options?: RequestInit,
): Promise<mailboxesAccessesRetrieveResponse> => {
  return fetchAPI<mailboxesAccessesRetrieveResponse>(
    getMailboxesAccessesRetrieveUrl(mailboxId, id),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesAccessesRetrieveQueryKey = (
  mailboxId?: string,
  id?: string,
) => {
  return [`/api/v1.0/mailboxes/${mailboxId}/accesses/${id}/`] as const;
};

export const getMailboxesAccessesRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesAccessesRetrieve>>,
  TError = unknown,
>(
  mailboxId: string,
  id: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getMailboxesAccessesRetrieveQueryKey(mailboxId, id);

  const queryFn: QueryFunction<
    Awaited<ReturnType<typeof mailboxesAccessesRetrieve>>
  > = ({ signal }) =>
    mailboxesAccessesRetrieve(mailboxId, id, { signal, ...requestOptions });

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

export type MailboxesAccessesRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesAccessesRetrieve>>
>;
export type MailboxesAccessesRetrieveQueryError = unknown;

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

export function useMailboxesAccessesRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesAccessesRetrieve>>,
  TError = unknown,
>(
  mailboxId: string,
  id: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesAccessesRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesAccessesRetrieveQueryOptions(
    mailboxId,
    id,
    options,
  );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * ViewSet for managing MailboxAccess records for a specific Mailbox.
The mailbox_id is expected as part of the URL.
Access is allowed if the user has MailboxAccess (ADMIN role)
to the target Mailbox itself, or is a domain admin of the mailbox's domain.
 */
export type mailboxesAccessesUpdateResponse200 = {
  data: MailboxAccessWrite;
  status: 200;
};

export type mailboxesAccessesUpdateResponseSuccess =
  mailboxesAccessesUpdateResponse200 & {
    headers: Headers;
  };
export type mailboxesAccessesUpdateResponse =
  mailboxesAccessesUpdateResponseSuccess;

export const getMailboxesAccessesUpdateUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/accesses/${id}/`;
};

export const mailboxesAccessesUpdate = async (
  mailboxId: string,
  id: string,
  mailboxAccessWriteRequest: MailboxAccessWriteRequest,
  options?: RequestInit,
): Promise<mailboxesAccessesUpdateResponse> => {
  return fetchAPI<mailboxesAccessesUpdateResponse>(
    getMailboxesAccessesUpdateUrl(mailboxId, id),
    {
      ...options,
      method: "PUT",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(mailboxAccessWriteRequest),
    },
  );
};

export const getMailboxesAccessesUpdateMutationOptions = <
  TError = unknown,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof mailboxesAccessesUpdate>>,
    TError,
    { mailboxId: string; id: string; data: MailboxAccessWriteRequest },
    TContext
  >;
  request?: SecondParameter<typeof fetchAPI>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof mailboxesAccessesUpdate>>,
  TError,
  { mailboxId: string; id: string; data: MailboxAccessWriteRequest },
  TContext
> => {
  const mutationKey = ["mailboxesAccessesUpdate"];
  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 mailboxesAccessesUpdate>>,
    { mailboxId: string; id: string; data: MailboxAccessWriteRequest }
  > = (props) => {
    const { mailboxId, id, data } = props ?? {};

    return mailboxesAccessesUpdate(mailboxId, id, data, requestOptions);
  };

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

export type MailboxesAccessesUpdateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesAccessesUpdate>>
>;
export type MailboxesAccessesUpdateMutationBody = MailboxAccessWriteRequest;
export type MailboxesAccessesUpdateMutationError = unknown;

export const useMailboxesAccessesUpdate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesAccessesUpdate>>,
      TError,
      { mailboxId: string; id: string; data: MailboxAccessWriteRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesAccessesUpdate>>,
  TError,
  { mailboxId: string; id: string; data: MailboxAccessWriteRequest },
  TContext
> => {
  const mutationOptions = getMailboxesAccessesUpdateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * ViewSet for managing MailboxAccess records for a specific Mailbox.
The mailbox_id is expected as part of the URL.
Access is allowed if the user has MailboxAccess (ADMIN role)
to the target Mailbox itself, or is a domain admin of the mailbox's domain.
 */
export type mailboxesAccessesPartialUpdateResponse200 = {
  data: MailboxAccessWrite;
  status: 200;
};

export type mailboxesAccessesPartialUpdateResponseSuccess =
  mailboxesAccessesPartialUpdateResponse200 & {
    headers: Headers;
  };
export type mailboxesAccessesPartialUpdateResponse =
  mailboxesAccessesPartialUpdateResponseSuccess;

export const getMailboxesAccessesPartialUpdateUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/accesses/${id}/`;
};

export const mailboxesAccessesPartialUpdate = async (
  mailboxId: string,
  id: string,
  patchedMailboxAccessWriteRequest: PatchedMailboxAccessWriteRequest,
  options?: RequestInit,
): Promise<mailboxesAccessesPartialUpdateResponse> => {
  return fetchAPI<mailboxesAccessesPartialUpdateResponse>(
    getMailboxesAccessesPartialUpdateUrl(mailboxId, id),
    {
      ...options,
      method: "PATCH",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(patchedMailboxAccessWriteRequest),
    },
  );
};

export const getMailboxesAccessesPartialUpdateMutationOptions = <
  TError = unknown,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof mailboxesAccessesPartialUpdate>>,
    TError,
    { mailboxId: string; id: string; data: PatchedMailboxAccessWriteRequest },
    TContext
  >;
  request?: SecondParameter<typeof fetchAPI>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof mailboxesAccessesPartialUpdate>>,
  TError,
  { mailboxId: string; id: string; data: PatchedMailboxAccessWriteRequest },
  TContext
> => {
  const mutationKey = ["mailboxesAccessesPartialUpdate"];
  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 mailboxesAccessesPartialUpdate>>,
    { mailboxId: string; id: string; data: PatchedMailboxAccessWriteRequest }
  > = (props) => {
    const { mailboxId, id, data } = props ?? {};

    return mailboxesAccessesPartialUpdate(mailboxId, id, data, requestOptions);
  };

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

export type MailboxesAccessesPartialUpdateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesAccessesPartialUpdate>>
>;
export type MailboxesAccessesPartialUpdateMutationBody =
  PatchedMailboxAccessWriteRequest;
export type MailboxesAccessesPartialUpdateMutationError = unknown;

export const useMailboxesAccessesPartialUpdate = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesAccessesPartialUpdate>>,
      TError,
      { mailboxId: string; id: string; data: PatchedMailboxAccessWriteRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesAccessesPartialUpdate>>,
  TError,
  { mailboxId: string; id: string; data: PatchedMailboxAccessWriteRequest },
  TContext
> => {
  const mutationOptions =
    getMailboxesAccessesPartialUpdateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * ViewSet for managing MailboxAccess records for a specific Mailbox.
The mailbox_id is expected as part of the URL.
Access is allowed if the user has MailboxAccess (ADMIN role)
to the target Mailbox itself, or is a domain admin of the mailbox's domain.
 */
export type mailboxesAccessesDestroyResponse204 = {
  data: void;
  status: 204;
};

export type mailboxesAccessesDestroyResponseSuccess =
  mailboxesAccessesDestroyResponse204 & {
    headers: Headers;
  };
export type mailboxesAccessesDestroyResponse =
  mailboxesAccessesDestroyResponseSuccess;

export const getMailboxesAccessesDestroyUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/accesses/${id}/`;
};

export const mailboxesAccessesDestroy = async (
  mailboxId: string,
  id: string,
  options?: RequestInit,
): Promise<mailboxesAccessesDestroyResponse> => {
  return fetchAPI<mailboxesAccessesDestroyResponse>(
    getMailboxesAccessesDestroyUrl(mailboxId, id),
    {
      ...options,
      method: "DELETE",
    },
  );
};

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

    return mailboxesAccessesDestroy(mailboxId, id, requestOptions);
  };

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

export type MailboxesAccessesDestroyMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesAccessesDestroy>>
>;

export type MailboxesAccessesDestroyMutationError = unknown;

export const useMailboxesAccessesDestroy = <
  TError = unknown,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesAccessesDestroy>>,
      TError,
      { mailboxId: string; id: string },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesAccessesDestroy>>,
  TError,
  { mailboxId: string; id: string },
  TContext
> => {
  const mutationOptions = getMailboxesAccessesDestroyMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
