/**
 * 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 {
  CalendarAddEventRequestRequest,
  CalendarAddEventResponse,
  CalendarConflictsRequestRequest,
  CalendarConflictsResponse,
  CalendarListResponse,
  CalendarRsvpRequestRequest,
  CalendarRsvpResponse,
  MailboxesCalendarAddCreate400,
  MailboxesCalendarAddCreate503,
  MailboxesCalendarCalendarsRetrieve403,
  MailboxesCalendarCalendarsRetrieve502,
  MailboxesCalendarConflictsCreate400,
  MailboxesCalendarConflictsCreate502,
  MailboxesCalendarRsvpCreate400,
  MailboxesCalendarRsvpCreate503,
} from ".././models";

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

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

/**
 * Add an event to the mailbox's CalDAV calendar via a background task.
 */
export type mailboxesCalendarAddCreateResponse200 = {
  data: CalendarAddEventResponse;
  status: 200;
};

export type mailboxesCalendarAddCreateResponse400 = {
  data: MailboxesCalendarAddCreate400;
  status: 400;
};

export type mailboxesCalendarAddCreateResponse503 = {
  data: MailboxesCalendarAddCreate503;
  status: 503;
};

export type mailboxesCalendarAddCreateResponseSuccess =
  mailboxesCalendarAddCreateResponse200 & {
    headers: Headers;
  };
export type mailboxesCalendarAddCreateResponseError = (
  | mailboxesCalendarAddCreateResponse400
  | mailboxesCalendarAddCreateResponse503
) & {
  headers: Headers;
};

export type mailboxesCalendarAddCreateResponse =
  | mailboxesCalendarAddCreateResponseSuccess
  | mailboxesCalendarAddCreateResponseError;

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

export const mailboxesCalendarAddCreate = async (
  mailboxId: string,
  calendarAddEventRequestRequest: CalendarAddEventRequestRequest,
  options?: RequestInit,
): Promise<mailboxesCalendarAddCreateResponse> => {
  return fetchAPI<mailboxesCalendarAddCreateResponse>(
    getMailboxesCalendarAddCreateUrl(mailboxId),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(calendarAddEventRequestRequest),
    },
  );
};

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

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

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

export type MailboxesCalendarAddCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesCalendarAddCreate>>
>;
export type MailboxesCalendarAddCreateMutationBody =
  CalendarAddEventRequestRequest;
export type MailboxesCalendarAddCreateMutationError = ErrorType<
  MailboxesCalendarAddCreate400 | MailboxesCalendarAddCreate503
>;

export const useMailboxesCalendarAddCreate = <
  TError = ErrorType<
    MailboxesCalendarAddCreate400 | MailboxesCalendarAddCreate503
  >,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesCalendarAddCreate>>,
      TError,
      { mailboxId: string; data: CalendarAddEventRequestRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesCalendarAddCreate>>,
  TError,
  { mailboxId: string; data: CalendarAddEventRequestRequest },
  TContext
> => {
  const mutationOptions = getMailboxesCalendarAddCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * Return the list of calendars available for the mailbox.
 */
export type mailboxesCalendarCalendarsRetrieveResponse200 = {
  data: CalendarListResponse;
  status: 200;
};

export type mailboxesCalendarCalendarsRetrieveResponse403 = {
  data: MailboxesCalendarCalendarsRetrieve403;
  status: 403;
};

export type mailboxesCalendarCalendarsRetrieveResponse502 = {
  data: MailboxesCalendarCalendarsRetrieve502;
  status: 502;
};

export type mailboxesCalendarCalendarsRetrieveResponseSuccess =
  mailboxesCalendarCalendarsRetrieveResponse200 & {
    headers: Headers;
  };
export type mailboxesCalendarCalendarsRetrieveResponseError = (
  | mailboxesCalendarCalendarsRetrieveResponse403
  | mailboxesCalendarCalendarsRetrieveResponse502
) & {
  headers: Headers;
};

export type mailboxesCalendarCalendarsRetrieveResponse =
  | mailboxesCalendarCalendarsRetrieveResponseSuccess
  | mailboxesCalendarCalendarsRetrieveResponseError;

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

export const mailboxesCalendarCalendarsRetrieve = async (
  mailboxId: string,
  options?: RequestInit,
): Promise<mailboxesCalendarCalendarsRetrieveResponse> => {
  return fetchAPI<mailboxesCalendarCalendarsRetrieveResponse>(
    getMailboxesCalendarCalendarsRetrieveUrl(mailboxId),
    {
      ...options,
      method: "GET",
    },
  );
};

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

export const getMailboxesCalendarCalendarsRetrieveQueryOptions = <
  TData = Awaited<ReturnType<typeof mailboxesCalendarCalendarsRetrieve>>,
  TError = ErrorType<
    | MailboxesCalendarCalendarsRetrieve403
    | MailboxesCalendarCalendarsRetrieve502
  >,
>(
  mailboxId: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesCalendarCalendarsRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getMailboxesCalendarCalendarsRetrieveQueryKey(mailboxId);

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

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

export type MailboxesCalendarCalendarsRetrieveQueryResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesCalendarCalendarsRetrieve>>
>;
export type MailboxesCalendarCalendarsRetrieveQueryError = ErrorType<
  MailboxesCalendarCalendarsRetrieve403 | MailboxesCalendarCalendarsRetrieve502
>;

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

export function useMailboxesCalendarCalendarsRetrieve<
  TData = Awaited<ReturnType<typeof mailboxesCalendarCalendarsRetrieve>>,
  TError = ErrorType<
    | MailboxesCalendarCalendarsRetrieve403
    | MailboxesCalendarCalendarsRetrieve502
  >,
>(
  mailboxId: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof mailboxesCalendarCalendarsRetrieve>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getMailboxesCalendarCalendarsRetrieveQueryOptions(
    mailboxId,
    options,
  );

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

  query.queryKey = queryOptions.queryKey;

  return query;
}

/**
 * Return a list of events overlapping the requested time range.
 */
export type mailboxesCalendarConflictsCreateResponse200 = {
  data: CalendarConflictsResponse;
  status: 200;
};

export type mailboxesCalendarConflictsCreateResponse400 = {
  data: MailboxesCalendarConflictsCreate400;
  status: 400;
};

export type mailboxesCalendarConflictsCreateResponse502 = {
  data: MailboxesCalendarConflictsCreate502;
  status: 502;
};

export type mailboxesCalendarConflictsCreateResponseSuccess =
  mailboxesCalendarConflictsCreateResponse200 & {
    headers: Headers;
  };
export type mailboxesCalendarConflictsCreateResponseError = (
  | mailboxesCalendarConflictsCreateResponse400
  | mailboxesCalendarConflictsCreateResponse502
) & {
  headers: Headers;
};

export type mailboxesCalendarConflictsCreateResponse =
  | mailboxesCalendarConflictsCreateResponseSuccess
  | mailboxesCalendarConflictsCreateResponseError;

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

export const mailboxesCalendarConflictsCreate = async (
  mailboxId: string,
  calendarConflictsRequestRequest: CalendarConflictsRequestRequest,
  options?: RequestInit,
): Promise<mailboxesCalendarConflictsCreateResponse> => {
  return fetchAPI<mailboxesCalendarConflictsCreateResponse>(
    getMailboxesCalendarConflictsCreateUrl(mailboxId),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(calendarConflictsRequestRequest),
    },
  );
};

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

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

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

export type MailboxesCalendarConflictsCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesCalendarConflictsCreate>>
>;
export type MailboxesCalendarConflictsCreateMutationBody =
  CalendarConflictsRequestRequest;
export type MailboxesCalendarConflictsCreateMutationError = ErrorType<
  MailboxesCalendarConflictsCreate400 | MailboxesCalendarConflictsCreate502
>;

export const useMailboxesCalendarConflictsCreate = <
  TError = ErrorType<
    MailboxesCalendarConflictsCreate400 | MailboxesCalendarConflictsCreate502
  >,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesCalendarConflictsCreate>>,
      TError,
      { mailboxId: string; data: CalendarConflictsRequestRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesCalendarConflictsCreate>>,
  TError,
  { mailboxId: string; data: CalendarConflictsRequestRequest },
  TContext
> => {
  const mutationOptions =
    getMailboxesCalendarConflictsCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
/**
 * Submit an RSVP response via a background CalDAV task.
 */
export type mailboxesCalendarRsvpCreateResponse200 = {
  data: CalendarRsvpResponse;
  status: 200;
};

export type mailboxesCalendarRsvpCreateResponse400 = {
  data: MailboxesCalendarRsvpCreate400;
  status: 400;
};

export type mailboxesCalendarRsvpCreateResponse503 = {
  data: MailboxesCalendarRsvpCreate503;
  status: 503;
};

export type mailboxesCalendarRsvpCreateResponseSuccess =
  mailboxesCalendarRsvpCreateResponse200 & {
    headers: Headers;
  };
export type mailboxesCalendarRsvpCreateResponseError = (
  | mailboxesCalendarRsvpCreateResponse400
  | mailboxesCalendarRsvpCreateResponse503
) & {
  headers: Headers;
};

export type mailboxesCalendarRsvpCreateResponse =
  | mailboxesCalendarRsvpCreateResponseSuccess
  | mailboxesCalendarRsvpCreateResponseError;

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

export const mailboxesCalendarRsvpCreate = async (
  mailboxId: string,
  calendarRsvpRequestRequest: CalendarRsvpRequestRequest,
  options?: RequestInit,
): Promise<mailboxesCalendarRsvpCreateResponse> => {
  return fetchAPI<mailboxesCalendarRsvpCreateResponse>(
    getMailboxesCalendarRsvpCreateUrl(mailboxId),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(calendarRsvpRequestRequest),
    },
  );
};

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

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

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

export type MailboxesCalendarRsvpCreateMutationResult = NonNullable<
  Awaited<ReturnType<typeof mailboxesCalendarRsvpCreate>>
>;
export type MailboxesCalendarRsvpCreateMutationBody =
  CalendarRsvpRequestRequest;
export type MailboxesCalendarRsvpCreateMutationError = ErrorType<
  MailboxesCalendarRsvpCreate400 | MailboxesCalendarRsvpCreate503
>;

export const useMailboxesCalendarRsvpCreate = <
  TError = ErrorType<
    MailboxesCalendarRsvpCreate400 | MailboxesCalendarRsvpCreate503
  >,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof mailboxesCalendarRsvpCreate>>,
      TError,
      { mailboxId: string; data: CalendarRsvpRequestRequest },
      TContext
    >;
    request?: SecondParameter<typeof fetchAPI>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof mailboxesCalendarRsvpCreate>>,
  TError,
  { mailboxId: string; data: CalendarRsvpRequestRequest },
  TContext
> => {
  const mutationOptions =
    getMailboxesCalendarRsvpCreateMutationOptions(options);

  return useMutation(mutationOptions, queryClient);
};
