/**
 * 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 {
  Mailbox,
  MailboxLight,
  MailboxResponseTimes,
  MailboxResponseTimesByLabel,
  MailboxStatsOverview,
  MailboxStorageStats,
  MailboxesImageProxyListParams,
  MailboxesMessageTemplatesAvailableListParams,
  MailboxesMessageTemplatesListParams,
  MailboxesMessageTemplatesRenderRetrieve200,
  MailboxesMessageTemplatesRenderRetrieveParams,
  MailboxesMessageTemplatesRetrieveParams,
  MailboxesSearchListParams,
  MailboxesStatsOverviewRetrieveParams,
  MailboxesStatsResponseTimesByLabelRetrieveParams,
  MailboxesStatsResponseTimesRetrieveParams,
  MessageTemplate,
  MessageTemplateRequest,
  PatchedMailboxNameUpdateRequest,
  PatchedMessageTemplateRequest,
  ReadMessageTemplate,
} from ".././models";

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

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

/**
 * ViewSet for Mailbox model.
 */
export type mailboxesListResponse200 = {
  data: Mailbox[];
  status: 200;
};

export type mailboxesListResponseSuccess = mailboxesListResponse200 & {
  headers: Headers;
};
export type mailboxesListResponse = mailboxesListResponseSuccess;

export const getMailboxesListUrl = () => {
  return `/api/v1.0/mailboxes/`;
};

export const mailboxesList = async (
  options?: RequestInit,
): Promise<mailboxesListResponse> => {
  return fetchAPI<mailboxesListResponse>(getMailboxesListUrl(), {
    ...options,
    method: "GET",
  });
};

export const getMailboxesListQueryKey = () => {
  return [`/api/v1.0/mailboxes/`] as const;
};

export const getMailboxesListQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesList>>,
  TError = ErrorType<unknown>,
>(options?: {
  query?: Partial<
    UseQueryOptions<Awaited<ReturnType<typeof mailboxesList>>, TError, TData>
  >;
  request?: SecondParameter<typeof fetchAPI>;
}) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type MailboxesListQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesList>>
>;
export type MailboxesListQueryError = ErrorType<unknown>;

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

export function useMailboxesList<
  TData = Awaited<ReturnType<typeof mailboxesList>>,
  TError = ErrorType<unknown>,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<Awaited<ReturnType<typeof mailboxesList>>, TError, TData>
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesListQueryOptions(options);

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Proxy an external image through the server.

        This endpoint fetches images from external sources and serves them
        through the application to protect user privacy. Requires the
        IMAGE_PROXY_ENABLED environment variable to be set to true.
        
 */
export type mailboxesImageProxyListResponse200 = {
  data: void;
  status: 200;
};

export type mailboxesImageProxyListResponse400 = {
  data: void;
  status: 400;
};

export type mailboxesImageProxyListResponse403 = {
  data: void;
  status: 403;
};

export type mailboxesImageProxyListResponse413 = {
  data: void;
  status: 413;
};

export type mailboxesImageProxyListResponse502 = {
  data: void;
  status: 502;
};

export type mailboxesImageProxyListResponseSuccess =
  mailboxesImageProxyListResponse200 & {
    headers: Headers;
  };
export type mailboxesImageProxyListResponseError = (
  | mailboxesImageProxyListResponse400
  | mailboxesImageProxyListResponse403
  | mailboxesImageProxyListResponse413
  | mailboxesImageProxyListResponse502
) & {
  headers: Headers;
};

export type mailboxesImageProxyListResponse =
  | mailboxesImageProxyListResponseSuccess
  | mailboxesImageProxyListResponseError;

export const getMailboxesImageProxyListUrl = (
  mailboxId: string,
  params: MailboxesImageProxyListParams,
) => {
  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}/image-proxy/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${mailboxId}/image-proxy/`;
};

export const mailboxesImageProxyList = async (
  mailboxId: string,
  params: MailboxesImageProxyListParams,
  options?: RequestInit,
): Promise<mailboxesImageProxyListResponse> => {
  return fetchAPI<mailboxesImageProxyListResponse>(
    getMailboxesImageProxyListUrl(mailboxId, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesImageProxyListQueryKey = (
  mailboxId?: string,
  params?: MailboxesImageProxyListParams,
) => {
  return [
    `/api/v1.0/mailboxes/${mailboxId}/image-proxy/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getMailboxesImageProxyListQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesImageProxyList>>,
  TError = ErrorType<void>,
>(
  mailboxId: string,
  params: MailboxesImageProxyListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesImageProxyList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type MailboxesImageProxyListQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesImageProxyList>>
>;
export type MailboxesImageProxyListQueryError = ErrorType<void>;

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

export function useMailboxesImageProxyList<
  TData = Awaited<ReturnType<typeof mailboxesImageProxyList>>,
  TError = ErrorType<void>,
>(
  mailboxId: string,
  params: MailboxesImageProxyListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesImageProxyList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesImageProxyListQueryOptions(
    mailboxId,
    params,
    options,
  );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * List message templates for a mailbox.
 */
export type mailboxesMessageTemplatesListResponse200 = {
  data: ReadMessageTemplate[];
  status: 200;
};

export type mailboxesMessageTemplatesListResponseSuccess =
  mailboxesMessageTemplatesListResponse200 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesListResponse =
  mailboxesMessageTemplatesListResponseSuccess;

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

  Object.entries(params || {}).forEach(([key, value]) => {
    const explodeParameters = ["type"];

    if (Array.isArray(value) && explodeParameters.includes(key)) {
      value.forEach((v) => {
        normalizedParams.append(key, v === null ? "null" : v.toString());
      });
      return;
    }

    if (value !== undefined) {
      normalizedParams.append(key, value === null ? "null" : value.toString());
    }
  });

  const stringifiedParams = normalizedParams.toString();

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

export const mailboxesMessageTemplatesList = async (
  mailboxId: string,
  params?: MailboxesMessageTemplatesListParams,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesListResponse> => {
  return fetchAPI<mailboxesMessageTemplatesListResponse>(
    getMailboxesMessageTemplatesListUrl(mailboxId, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesMessageTemplatesListQueryKey = (
  mailboxId?: string,
  params?: MailboxesMessageTemplatesListParams,
) => {
  return [
    `/api/v1.0/mailboxes/${mailboxId}/message-templates/`,
    ...(params ? [params] : []),
  ] as const;
};

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

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

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

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

export type MailboxesMessageTemplatesListQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesList>>
>;
export type MailboxesMessageTemplatesListQueryError = ErrorType<unknown>;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Create a template and return a read-serialized response.
 */
export type mailboxesMessageTemplatesCreateResponse201 = {
  data: MessageTemplate;
  status: 201;
};

export type mailboxesMessageTemplatesCreateResponseSuccess =
  mailboxesMessageTemplatesCreateResponse201 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesCreateResponse =
  mailboxesMessageTemplatesCreateResponseSuccess;

export const getMailboxesMessageTemplatesCreateUrl = (mailboxId: string) => {
  return `/api/v1.0/mailboxes/${mailboxId}/message-templates/`;
};

export const mailboxesMessageTemplatesCreate = async (
  mailboxId: string,
  messageTemplateRequest: MessageTemplateRequest,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesCreateResponse> => {
  return fetchAPI<mailboxesMessageTemplatesCreateResponse>(
    getMailboxesMessageTemplatesCreateUrl(mailboxId),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(messageTemplateRequest),
    },
  );
};

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

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

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

export type MailboxesMessageTemplatesCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesCreate>>
>;
export type MailboxesMessageTemplatesCreateMutationBody =
  MessageTemplateRequest;
export type MailboxesMessageTemplatesCreateMutationError = ErrorType<unknown>;

export const useMailboxesMessageTemplatesCreate = <
  TError = ErrorType<unknown>,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesMessageTemplatesCreate>>,
      TError,
      { mailboxId: string; data: MessageTemplateRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesCreate>>,
  TError,
  { mailboxId: string; data: MessageTemplateRequest },
  TContext
> => {
  const mutationOptions =
    getMailboxesMessageTemplatesCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * Retrieve a message template.
 */
export type mailboxesMessageTemplatesRetrieveResponse200 = {
  data: ReadMessageTemplate;
  status: 200;
};

export type mailboxesMessageTemplatesRetrieveResponseSuccess =
  mailboxesMessageTemplatesRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesRetrieveResponse =
  mailboxesMessageTemplatesRetrieveResponseSuccess;

export const getMailboxesMessageTemplatesRetrieveUrl = (
  mailboxId: string,
  id: string,
  params?: MailboxesMessageTemplatesRetrieveParams,
) => {
  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}/message-templates/${id}/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/`;
};

export const mailboxesMessageTemplatesRetrieve = async (
  mailboxId: string,
  id: string,
  params?: MailboxesMessageTemplatesRetrieveParams,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesRetrieveResponse> => {
  return fetchAPI<mailboxesMessageTemplatesRetrieveResponse>(
    getMailboxesMessageTemplatesRetrieveUrl(mailboxId, id, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesMessageTemplatesRetrieveQueryKey = (
  mailboxId?: string,
  id?: string,
  params?: MailboxesMessageTemplatesRetrieveParams,
) => {
  return [
    `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/`,
    ...(params ? [params] : []),
  ] as const;
};

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

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

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

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

export type MailboxesMessageTemplatesRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesRetrieve>>
>;
export type MailboxesMessageTemplatesRetrieveQueryError = ErrorType<unknown>;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Update a template and return a read-serialized response.
 */
export type mailboxesMessageTemplatesUpdateResponse200 = {
  data: MessageTemplate;
  status: 200;
};

export type mailboxesMessageTemplatesUpdateResponseSuccess =
  mailboxesMessageTemplatesUpdateResponse200 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesUpdateResponse =
  mailboxesMessageTemplatesUpdateResponseSuccess;

export const getMailboxesMessageTemplatesUpdateUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/`;
};

export const mailboxesMessageTemplatesUpdate = async (
  mailboxId: string,
  id: string,
  messageTemplateRequest: MessageTemplateRequest,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesUpdateResponse> => {
  return fetchAPI<mailboxesMessageTemplatesUpdateResponse>(
    getMailboxesMessageTemplatesUpdateUrl(mailboxId, id),
    {
      ...options,
      method: "PUT",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(messageTemplateRequest),
    },
  );
};

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

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

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

export type MailboxesMessageTemplatesUpdateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesUpdate>>
>;
export type MailboxesMessageTemplatesUpdateMutationBody =
  MessageTemplateRequest;
export type MailboxesMessageTemplatesUpdateMutationError = ErrorType<unknown>;

export const useMailboxesMessageTemplatesUpdate = <
  TError = ErrorType<unknown>,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesMessageTemplatesUpdate>>,
      TError,
      { mailboxId: string; id: string; data: MessageTemplateRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesUpdate>>,
  TError,
  { mailboxId: string; id: string; data: MessageTemplateRequest },
  TContext
> => {
  const mutationOptions =
    getMailboxesMessageTemplatesUpdateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * ViewSet for managing message templates for a mailbox.
 */
export type mailboxesMessageTemplatesPartialUpdateResponse200 = {
  data: MessageTemplate;
  status: 200;
};

export type mailboxesMessageTemplatesPartialUpdateResponseSuccess =
  mailboxesMessageTemplatesPartialUpdateResponse200 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesPartialUpdateResponse =
  mailboxesMessageTemplatesPartialUpdateResponseSuccess;

export const getMailboxesMessageTemplatesPartialUpdateUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/`;
};

export const mailboxesMessageTemplatesPartialUpdate = async (
  mailboxId: string,
  id: string,
  patchedMessageTemplateRequest: PatchedMessageTemplateRequest,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesPartialUpdateResponse> => {
  return fetchAPI<mailboxesMessageTemplatesPartialUpdateResponse>(
    getMailboxesMessageTemplatesPartialUpdateUrl(mailboxId, id),
    {
      ...options,
      method: "PATCH",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(patchedMessageTemplateRequest),
    },
  );
};

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

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

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

export type MailboxesMessageTemplatesPartialUpdateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesPartialUpdate>>
>;
export type MailboxesMessageTemplatesPartialUpdateMutationBody =
  PatchedMessageTemplateRequest;
export type MailboxesMessageTemplatesPartialUpdateMutationError =
  ErrorType<unknown>;

export const useMailboxesMessageTemplatesPartialUpdate = <
  TError = ErrorType<unknown>,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesMessageTemplatesPartialUpdate>>,
      TError,
      { mailboxId: string; id: string; data: PatchedMessageTemplateRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesPartialUpdate>>,
  TError,
  { mailboxId: string; id: string; data: PatchedMessageTemplateRequest },
  TContext
> => {
  const mutationOptions =
    getMailboxesMessageTemplatesPartialUpdateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * ViewSet for managing message templates for a mailbox.
 */
export type mailboxesMessageTemplatesDestroyResponse204 = {
  data: void;
  status: 204;
};

export type mailboxesMessageTemplatesDestroyResponseSuccess =
  mailboxesMessageTemplatesDestroyResponse204 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesDestroyResponse =
  mailboxesMessageTemplatesDestroyResponseSuccess;

export const getMailboxesMessageTemplatesDestroyUrl = (
  mailboxId: string,
  id: string,
) => {
  return `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/`;
};

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

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

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

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

export type MailboxesMessageTemplatesDestroyMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesDestroy>>
>;

export type MailboxesMessageTemplatesDestroyMutationError = ErrorType<unknown>;

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

  return useMutation(mutationOptions, queryClient);
};
/**
 * Render the template's html and text bodies with placeholders resolved from the mailbox and the authenticated user (name, user_name, custom attributes). When a draft message_id is provided, message-level placeholders (recipient_name) are also resolved. Unresolved placeholders keep their {placeholder} token.
 * @summary Render a message template
 */
export type mailboxesMessageTemplatesRenderRetrieveResponse200 = {
  data: MailboxesMessageTemplatesRenderRetrieve200;
  status: 200;
};

export type mailboxesMessageTemplatesRenderRetrieveResponseSuccess =
  mailboxesMessageTemplatesRenderRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesRenderRetrieveResponse =
  mailboxesMessageTemplatesRenderRetrieveResponseSuccess;

export const getMailboxesMessageTemplatesRenderRetrieveUrl = (
  mailboxId: string,
  id: string,
  params?: MailboxesMessageTemplatesRenderRetrieveParams,
) => {
  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}/message-templates/${id}/render/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/render/`;
};

export const mailboxesMessageTemplatesRenderRetrieve = async (
  mailboxId: string,
  id: string,
  params?: MailboxesMessageTemplatesRenderRetrieveParams,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesRenderRetrieveResponse> => {
  return fetchAPI<mailboxesMessageTemplatesRenderRetrieveResponse>(
    getMailboxesMessageTemplatesRenderRetrieveUrl(mailboxId, id, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesMessageTemplatesRenderRetrieveQueryKey = (
  mailboxId?: string,
  id?: string,
  params?: MailboxesMessageTemplatesRenderRetrieveParams,
) => {
  return [
    `/api/v1.0/mailboxes/${mailboxId}/message-templates/${id}/render/`,
    ...(params ? [params] : []),
  ] as const;
};

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

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

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

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

export type MailboxesMessageTemplatesRenderRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>
>;
export type MailboxesMessageTemplatesRenderRetrieveQueryError =
  ErrorType<unknown>;

export function useMailboxesMessageTemplatesRenderRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
  TError = ErrorType<unknown>,
>(
  mailboxId: string,
  id: string,
  params: undefined | MailboxesMessageTemplatesRenderRetrieveParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
          TError,
          Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useMailboxesMessageTemplatesRenderRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
  TError = ErrorType<unknown>,
>(
  mailboxId: string,
  id: string,
  params?: MailboxesMessageTemplatesRenderRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
          TError,
          Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useMailboxesMessageTemplatesRenderRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
  TError = ErrorType<unknown>,
>(
  mailboxId: string,
  id: string,
  params?: MailboxesMessageTemplatesRenderRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesMessageTemplatesRenderRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Render a message template
 */

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * List message templates.
 */
export type mailboxesMessageTemplatesAvailableListResponse200 = {
  data: ReadMessageTemplate[];
  status: 200;
};

export type mailboxesMessageTemplatesAvailableListResponseSuccess =
  mailboxesMessageTemplatesAvailableListResponse200 & {
    headers: Headers;
  };
export type mailboxesMessageTemplatesAvailableListResponse =
  mailboxesMessageTemplatesAvailableListResponseSuccess;

export const getMailboxesMessageTemplatesAvailableListUrl = (
  mailboxId: string,
  params?: MailboxesMessageTemplatesAvailableListParams,
) => {
  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}/message-templates/available/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${mailboxId}/message-templates/available/`;
};

export const mailboxesMessageTemplatesAvailableList = async (
  mailboxId: string,
  params?: MailboxesMessageTemplatesAvailableListParams,
  options?: RequestInit,
): Promise<mailboxesMessageTemplatesAvailableListResponse> => {
  return fetchAPI<mailboxesMessageTemplatesAvailableListResponse>(
    getMailboxesMessageTemplatesAvailableListUrl(mailboxId, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesMessageTemplatesAvailableListQueryKey = (
  mailboxId?: string,
  params?: MailboxesMessageTemplatesAvailableListParams,
) => {
  return [
    `/api/v1.0/mailboxes/${mailboxId}/message-templates/available/`,
    ...(params ? [params] : []),
  ] as const;
};

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

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

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

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

export type MailboxesMessageTemplatesAvailableListQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesMessageTemplatesAvailableList>>
>;
export type MailboxesMessageTemplatesAvailableListQueryError =
  ErrorType<unknown>;

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

export function useMailboxesMessageTemplatesAvailableList<
  TData = Awaited<ReturnType<typeof mailboxesMessageTemplatesAvailableList>>,
  TError = ErrorType<unknown>,
>(
  mailboxId: string,
  params?: MailboxesMessageTemplatesAvailableListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesMessageTemplatesAvailableList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesMessageTemplatesAvailableListQueryOptions(
    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 Mailbox model.
 */
export type mailboxesRetrieveResponse200 = {
  data: Mailbox;
  status: 200;
};

export type mailboxesRetrieveResponseSuccess = mailboxesRetrieveResponse200 & {
  headers: Headers;
};
export type mailboxesRetrieveResponse = mailboxesRetrieveResponseSuccess;

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

export const mailboxesRetrieve = async (
  id: string,
  options?: RequestInit,
): Promise<mailboxesRetrieveResponse> => {
  return fetchAPI<mailboxesRetrieveResponse>(getMailboxesRetrieveUrl(id), {
    ...options,
    method: "GET",
  });
};

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

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

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

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

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

export type MailboxesRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesRetrieve>>
>;
export type MailboxesRetrieveQueryError = ErrorType<unknown>;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Rename a mailbox (its display contact name). Mailbox admins only.

``partial=True`` keeps true PATCH semantics: omitting ``name`` is a no-op
rather than a 400, so the runtime matches the optional request schema.
 */
export type mailboxesPartialUpdateResponse200 = {
  data: Mailbox;
  status: 200;
};

export type mailboxesPartialUpdateResponseSuccess =
  mailboxesPartialUpdateResponse200 & {
    headers: Headers;
  };
export type mailboxesPartialUpdateResponse =
  mailboxesPartialUpdateResponseSuccess;

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

export const mailboxesPartialUpdate = async (
  id: string,
  patchedMailboxNameUpdateRequest: PatchedMailboxNameUpdateRequest,
  options?: RequestInit,
): Promise<mailboxesPartialUpdateResponse> => {
  return fetchAPI<mailboxesPartialUpdateResponse>(
    getMailboxesPartialUpdateUrl(id),
    {
      ...options,
      method: "PATCH",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(patchedMailboxNameUpdateRequest),
    },
  );
};

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

    return mailboxesPartialUpdate(id, data, requestOptions);
  };

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

export type MailboxesPartialUpdateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesPartialUpdate>>
>;
export type MailboxesPartialUpdateMutationBody =
  PatchedMailboxNameUpdateRequest;
export type MailboxesPartialUpdateMutationError = ErrorType<unknown>;

export const useMailboxesPartialUpdate = <
  TError = ErrorType<unknown>,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesPartialUpdate>>,
      TError,
      { id: string; data: PatchedMailboxNameUpdateRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesPartialUpdate>>,
  TError,
  { id: string; data: PatchedMailboxNameUpdateRequest },
  TContext
> => {
  const mutationOptions = getMailboxesPartialUpdateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * Search mailboxes by domain, local part and contact name.

Query parameters:
- q: Optional search query for local part and contact name
 */
export type mailboxesSearchListResponse200 = {
  data: MailboxLight[];
  status: 200;
};

export type mailboxesSearchListResponseSuccess =
  mailboxesSearchListResponse200 & {
    headers: Headers;
  };
export type mailboxesSearchListResponse = mailboxesSearchListResponseSuccess;

export const getMailboxesSearchListUrl = (
  id: string,
  params?: MailboxesSearchListParams,
) => {
  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/${id}/search/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${id}/search/`;
};

export const mailboxesSearchList = async (
  id: string,
  params?: MailboxesSearchListParams,
  options?: RequestInit,
): Promise<mailboxesSearchListResponse> => {
  return fetchAPI<mailboxesSearchListResponse>(
    getMailboxesSearchListUrl(id, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesSearchListQueryKey = (
  id?: string,
  params?: MailboxesSearchListParams,
) => {
  return [
    `/api/v1.0/mailboxes/${id}/search/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getMailboxesSearchListQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesSearchList>>,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesSearchListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesSearchList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ?? getMailboxesSearchListQueryKey(id, params);

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

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

export type MailboxesSearchListQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesSearchList>>
>;
export type MailboxesSearchListQueryError = ErrorType<unknown>;

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

export function useMailboxesSearchList<
  TData = Awaited<ReturnType<typeof mailboxesSearchList>>,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesSearchListParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesSearchList>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesSearchListQueryOptions(id, params, options);

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Headline counts for the mailbox over the given timeframe: active
conversations, messages, and sent emails.
 */
export type mailboxesStatsOverviewRetrieveResponse200 = {
  data: MailboxStatsOverview;
  status: 200;
};

export type mailboxesStatsOverviewRetrieveResponseSuccess =
  mailboxesStatsOverviewRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesStatsOverviewRetrieveResponse =
  mailboxesStatsOverviewRetrieveResponseSuccess;

export const getMailboxesStatsOverviewRetrieveUrl = (
  id: string,
  params?: MailboxesStatsOverviewRetrieveParams,
) => {
  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/${id}/stats/overview/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${id}/stats/overview/`;
};

export const mailboxesStatsOverviewRetrieve = async (
  id: string,
  params?: MailboxesStatsOverviewRetrieveParams,
  options?: RequestInit,
): Promise<mailboxesStatsOverviewRetrieveResponse> => {
  return fetchAPI<mailboxesStatsOverviewRetrieveResponse>(
    getMailboxesStatsOverviewRetrieveUrl(id, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesStatsOverviewRetrieveQueryKey = (
  id?: string,
  params?: MailboxesStatsOverviewRetrieveParams,
) => {
  return [
    `/api/v1.0/mailboxes/${id}/stats/overview/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getMailboxesStatsOverviewRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesStatsOverviewRetrieve>>,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesStatsOverviewRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesStatsOverviewRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getMailboxesStatsOverviewRetrieveQueryKey(id, params);

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

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

export type MailboxesStatsOverviewRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesStatsOverviewRetrieve>>
>;
export type MailboxesStatsOverviewRetrieveQueryError = ErrorType<unknown>;

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

export function useMailboxesStatsOverviewRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesStatsOverviewRetrieve>>,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesStatsOverviewRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesStatsOverviewRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesStatsOverviewRetrieveQueryOptions(
    id,
    params,
    options,
  );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Average time between an incoming email and its first external reply,
globally and per author.

For each incoming email received in the period, the reply is the first
outgoing (non-draft, non-trashed) message in the same thread sent after
it — chronological matching by ``created_at``, the authoritative order
everywhere in the codebase. Emails with no later reply count as
unreplied. Authorship comes from ``Message.sender_user`` (the user who
sent the reply), falling back to the sender contact.
 */
export type mailboxesStatsResponseTimesRetrieveResponse200 = {
  data: MailboxResponseTimes;
  status: 200;
};

export type mailboxesStatsResponseTimesRetrieveResponseSuccess =
  mailboxesStatsResponseTimesRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesStatsResponseTimesRetrieveResponse =
  mailboxesStatsResponseTimesRetrieveResponseSuccess;

export const getMailboxesStatsResponseTimesRetrieveUrl = (
  id: string,
  params?: MailboxesStatsResponseTimesRetrieveParams,
) => {
  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/${id}/stats/response_times/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${id}/stats/response_times/`;
};

export const mailboxesStatsResponseTimesRetrieve = async (
  id: string,
  params?: MailboxesStatsResponseTimesRetrieveParams,
  options?: RequestInit,
): Promise<mailboxesStatsResponseTimesRetrieveResponse> => {
  return fetchAPI<mailboxesStatsResponseTimesRetrieveResponse>(
    getMailboxesStatsResponseTimesRetrieveUrl(id, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesStatsResponseTimesRetrieveQueryKey = (
  id?: string,
  params?: MailboxesStatsResponseTimesRetrieveParams,
) => {
  return [
    `/api/v1.0/mailboxes/${id}/stats/response_times/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getMailboxesStatsResponseTimesRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesStatsResponseTimesRetrieve>>,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesStatsResponseTimesRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesStatsResponseTimesRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getMailboxesStatsResponseTimesRetrieveQueryKey(id, params);

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

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

export type MailboxesStatsResponseTimesRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesStatsResponseTimesRetrieve>>
>;
export type MailboxesStatsResponseTimesRetrieveQueryError = ErrorType<unknown>;

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

export function useMailboxesStatsResponseTimesRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesStatsResponseTimesRetrieve>>,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesStatsResponseTimesRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesStatsResponseTimesRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesStatsResponseTimesRetrieveQueryOptions(
    id,
    params,
    options,
  );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Reply-time totals grouped by label.

Same incoming/reply model as ``stats/response_times`` but each incoming
email is counted once per label on its thread. Returns raw totals per
label (received, replied, summed response seconds); the client rolls
them up the label tree and derives averages and no-reply counts.
 */
export type mailboxesStatsResponseTimesByLabelRetrieveResponse200 = {
  data: MailboxResponseTimesByLabel;
  status: 200;
};

export type mailboxesStatsResponseTimesByLabelRetrieveResponseSuccess =
  mailboxesStatsResponseTimesByLabelRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesStatsResponseTimesByLabelRetrieveResponse =
  mailboxesStatsResponseTimesByLabelRetrieveResponseSuccess;

export const getMailboxesStatsResponseTimesByLabelRetrieveUrl = (
  id: string,
  params?: MailboxesStatsResponseTimesByLabelRetrieveParams,
) => {
  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/${id}/stats/response_times_by_label/?${stringifiedParams}`
    : `/api/v1.0/mailboxes/${id}/stats/response_times_by_label/`;
};

export const mailboxesStatsResponseTimesByLabelRetrieve = async (
  id: string,
  params?: MailboxesStatsResponseTimesByLabelRetrieveParams,
  options?: RequestInit,
): Promise<mailboxesStatsResponseTimesByLabelRetrieveResponse> => {
  return fetchAPI<mailboxesStatsResponseTimesByLabelRetrieveResponse>(
    getMailboxesStatsResponseTimesByLabelRetrieveUrl(id, params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesStatsResponseTimesByLabelRetrieveQueryKey = (
  id?: string,
  params?: MailboxesStatsResponseTimesByLabelRetrieveParams,
) => {
  return [
    `/api/v1.0/mailboxes/${id}/stats/response_times_by_label/`,
    ...(params ? [params] : []),
  ] as const;
};

export const getMailboxesStatsResponseTimesByLabelRetrieveQueryOptions = <
  TData = Awaited<
    ReturnType<typeof mailboxesStatsResponseTimesByLabelRetrieve>
  >,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesStatsResponseTimesByLabelRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesStatsResponseTimesByLabelRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getMailboxesStatsResponseTimesByLabelRetrieveQueryKey(id, params);

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

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

export type MailboxesStatsResponseTimesByLabelRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesStatsResponseTimesByLabelRetrieve>>
>;
export type MailboxesStatsResponseTimesByLabelRetrieveQueryError =
  ErrorType<unknown>;

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

export function useMailboxesStatsResponseTimesByLabelRetrieve<
  TData = Awaited<
    ReturnType<typeof mailboxesStatsResponseTimesByLabelRetrieve>
  >,
  TError = ErrorType<unknown>,
>(
  id: string,
  params?: MailboxesStatsResponseTimesByLabelRetrieveParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesStatsResponseTimesByLabelRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions =
    getMailboxesStatsResponseTimesByLabelRetrieveQueryOptions(
      id,
      params,
      options,
    );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Return total storage and top-100 largest threads for the mailbox.

Storage is computed using the same formula as the metrics endpoints:
``message_count * OVERHEAD + mime_blobs + draft_blobs
+ attachment_blobs + template_blobs``.

Lives under ``stats/`` for URL consistency, but backs the Storage
settings tab — which is not behind ``FEATURE_MAILBOX_STATS`` — so unlike
the sibling actions it deliberately omits ``_require_stats_feature()``.
The flag is enforced in code, not by the URL prefix.
 */
export type mailboxesStatsStorageRetrieveResponse200 = {
  data: MailboxStorageStats;
  status: 200;
};

export type mailboxesStatsStorageRetrieveResponseSuccess =
  mailboxesStatsStorageRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesStatsStorageRetrieveResponse =
  mailboxesStatsStorageRetrieveResponseSuccess;

export const getMailboxesStatsStorageRetrieveUrl = (id: string) => {
  return `/api/v1.0/mailboxes/${id}/stats/storage/`;
};

export const mailboxesStatsStorageRetrieve = async (
  id: string,
  options?: RequestInit,
): Promise<mailboxesStatsStorageRetrieveResponse> => {
  return fetchAPI<mailboxesStatsStorageRetrieveResponse>(
    getMailboxesStatsStorageRetrieveUrl(id),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getMailboxesStatsStorageRetrieveQueryKey = (id?: string) => {
  return [`/api/v1.0/mailboxes/${id}/stats/storage/`] as const;
};

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

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

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

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

export type MailboxesStatsStorageRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesStatsStorageRetrieve>>
>;
export type MailboxesStatsStorageRetrieveQueryError = ErrorType<unknown>;

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

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

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

  query.queryKey = queryOptions.queryKey;

  return query;
}
