/**
 * Generated by orval v8.3.0 🍺
 * Do not edit manually.
 * Mission Control API
 * OpenAPI spec version: 0.1.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 {
  HTTPValidationError,
  LimitOffsetPageTypeVarCustomizedTagRead,
  ListTagsApiV1TagsGetParams,
  OkResponse,
  TagCreate,
  TagRead,
  TagUpdate,
} from ".././model";

import { customFetch } from "../../mutator";

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

/**
 * List tags for the active organization.
 * @summary List Tags
 */
export type listTagsApiV1TagsGetResponse200 = {
  data: LimitOffsetPageTypeVarCustomizedTagRead;
  status: 200;
};

export type listTagsApiV1TagsGetResponse422 = {
  data: HTTPValidationError;
  status: 422;
};

export type listTagsApiV1TagsGetResponseSuccess =
  listTagsApiV1TagsGetResponse200 & {
    headers: Headers;
  };
export type listTagsApiV1TagsGetResponseError =
  listTagsApiV1TagsGetResponse422 & {
    headers: Headers;
  };

export type listTagsApiV1TagsGetResponse =
  | listTagsApiV1TagsGetResponseSuccess
  | listTagsApiV1TagsGetResponseError;

export const getListTagsApiV1TagsGetUrl = (
  params?: ListTagsApiV1TagsGetParams,
) => {
  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/tags?${stringifiedParams}`
    : `/api/v1/tags`;
};

export const listTagsApiV1TagsGet = async (
  params?: ListTagsApiV1TagsGetParams,
  options?: RequestInit,
): Promise<listTagsApiV1TagsGetResponse> => {
  return customFetch<listTagsApiV1TagsGetResponse>(
    getListTagsApiV1TagsGetUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getListTagsApiV1TagsGetQueryKey = (
  params?: ListTagsApiV1TagsGetParams,
) => {
  return [`/api/v1/tags`, ...(params ? [params] : [])] as const;
};

export const getListTagsApiV1TagsGetQueryOptions = <
  TData = Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
  TError = HTTPValidationError,
>(
  params?: ListTagsApiV1TagsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type ListTagsApiV1TagsGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof listTagsApiV1TagsGet>>
>;
export type ListTagsApiV1TagsGetQueryError = HTTPValidationError;

export function useListTagsApiV1TagsGet<
  TData = Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
  TError = HTTPValidationError,
>(
  params: undefined | ListTagsApiV1TagsGetParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
          TError,
          Awaited<ReturnType<typeof listTagsApiV1TagsGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useListTagsApiV1TagsGet<
  TData = Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
  TError = HTTPValidationError,
>(
  params?: ListTagsApiV1TagsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
          TError,
          Awaited<ReturnType<typeof listTagsApiV1TagsGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useListTagsApiV1TagsGet<
  TData = Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
  TError = HTTPValidationError,
>(
  params?: ListTagsApiV1TagsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary List Tags
 */

export function useListTagsApiV1TagsGet<
  TData = Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
  TError = HTTPValidationError,
>(
  params?: ListTagsApiV1TagsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listTagsApiV1TagsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getListTagsApiV1TagsGetQueryOptions(params, options);

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

  return { ...query, queryKey: queryOptions.queryKey };
}

/**
 * Create a tag within the active organization.
 * @summary Create Tag
 */
export type createTagApiV1TagsPostResponse200 = {
  data: TagRead;
  status: 200;
};

export type createTagApiV1TagsPostResponse422 = {
  data: HTTPValidationError;
  status: 422;
};

export type createTagApiV1TagsPostResponseSuccess =
  createTagApiV1TagsPostResponse200 & {
    headers: Headers;
  };
export type createTagApiV1TagsPostResponseError =
  createTagApiV1TagsPostResponse422 & {
    headers: Headers;
  };

export type createTagApiV1TagsPostResponse =
  | createTagApiV1TagsPostResponseSuccess
  | createTagApiV1TagsPostResponseError;

export const getCreateTagApiV1TagsPostUrl = () => {
  return `/api/v1/tags`;
};

export const createTagApiV1TagsPost = async (
  tagCreate: TagCreate,
  options?: RequestInit,
): Promise<createTagApiV1TagsPostResponse> => {
  return customFetch<createTagApiV1TagsPostResponse>(
    getCreateTagApiV1TagsPostUrl(),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(tagCreate),
    },
  );
};

export const getCreateTagApiV1TagsPostMutationOptions = <
  TError = HTTPValidationError,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof createTagApiV1TagsPost>>,
    TError,
    { data: TagCreate },
    TContext
  >;
  request?: SecondParameter<typeof customFetch>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof createTagApiV1TagsPost>>,
  TError,
  { data: TagCreate },
  TContext
> => {
  const mutationKey = ["createTagApiV1TagsPost"];
  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 createTagApiV1TagsPost>>,
    { data: TagCreate }
  > = (props) => {
    const { data } = props ?? {};

    return createTagApiV1TagsPost(data, requestOptions);
  };

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

export type CreateTagApiV1TagsPostMutationResult = NonNullable<
  Awaited<ReturnType<typeof createTagApiV1TagsPost>>
>;
export type CreateTagApiV1TagsPostMutationBody = TagCreate;
export type CreateTagApiV1TagsPostMutationError = HTTPValidationError;

/**
 * @summary Create Tag
 */
export const useCreateTagApiV1TagsPost = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof createTagApiV1TagsPost>>,
      TError,
      { data: TagCreate },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof createTagApiV1TagsPost>>,
  TError,
  { data: TagCreate },
  TContext
> => {
  return useMutation(
    getCreateTagApiV1TagsPostMutationOptions(options),
    queryClient,
  );
};
/**
 * Delete a tag and remove all associated tag links.
 * @summary Delete Tag
 */
export type deleteTagApiV1TagsTagIdDeleteResponse200 = {
  data: OkResponse;
  status: 200;
};

export type deleteTagApiV1TagsTagIdDeleteResponse422 = {
  data: HTTPValidationError;
  status: 422;
};

export type deleteTagApiV1TagsTagIdDeleteResponseSuccess =
  deleteTagApiV1TagsTagIdDeleteResponse200 & {
    headers: Headers;
  };
export type deleteTagApiV1TagsTagIdDeleteResponseError =
  deleteTagApiV1TagsTagIdDeleteResponse422 & {
    headers: Headers;
  };

export type deleteTagApiV1TagsTagIdDeleteResponse =
  | deleteTagApiV1TagsTagIdDeleteResponseSuccess
  | deleteTagApiV1TagsTagIdDeleteResponseError;

export const getDeleteTagApiV1TagsTagIdDeleteUrl = (tagId: string) => {
  return `/api/v1/tags/${tagId}`;
};

export const deleteTagApiV1TagsTagIdDelete = async (
  tagId: string,
  options?: RequestInit,
): Promise<deleteTagApiV1TagsTagIdDeleteResponse> => {
  return customFetch<deleteTagApiV1TagsTagIdDeleteResponse>(
    getDeleteTagApiV1TagsTagIdDeleteUrl(tagId),
    {
      ...options,
      method: "DELETE",
    },
  );
};

export const getDeleteTagApiV1TagsTagIdDeleteMutationOptions = <
  TError = HTTPValidationError,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof deleteTagApiV1TagsTagIdDelete>>,
    TError,
    { tagId: string },
    TContext
  >;
  request?: SecondParameter<typeof customFetch>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof deleteTagApiV1TagsTagIdDelete>>,
  TError,
  { tagId: string },
  TContext
> => {
  const mutationKey = ["deleteTagApiV1TagsTagIdDelete"];
  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 deleteTagApiV1TagsTagIdDelete>>,
    { tagId: string }
  > = (props) => {
    const { tagId } = props ?? {};

    return deleteTagApiV1TagsTagIdDelete(tagId, requestOptions);
  };

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

export type DeleteTagApiV1TagsTagIdDeleteMutationResult = NonNullable<
  Awaited<ReturnType<typeof deleteTagApiV1TagsTagIdDelete>>
>;

export type DeleteTagApiV1TagsTagIdDeleteMutationError = HTTPValidationError;

/**
 * @summary Delete Tag
 */
export const useDeleteTagApiV1TagsTagIdDelete = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof deleteTagApiV1TagsTagIdDelete>>,
      TError,
      { tagId: string },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof deleteTagApiV1TagsTagIdDelete>>,
  TError,
  { tagId: string },
  TContext
> => {
  return useMutation(
    getDeleteTagApiV1TagsTagIdDeleteMutationOptions(options),
    queryClient,
  );
};
/**
 * Get a single tag in the active organization.
 * @summary Get Tag
 */
export type getTagApiV1TagsTagIdGetResponse200 = {
  data: TagRead;
  status: 200;
};

export type getTagApiV1TagsTagIdGetResponse422 = {
  data: HTTPValidationError;
  status: 422;
};

export type getTagApiV1TagsTagIdGetResponseSuccess =
  getTagApiV1TagsTagIdGetResponse200 & {
    headers: Headers;
  };
export type getTagApiV1TagsTagIdGetResponseError =
  getTagApiV1TagsTagIdGetResponse422 & {
    headers: Headers;
  };

export type getTagApiV1TagsTagIdGetResponse =
  | getTagApiV1TagsTagIdGetResponseSuccess
  | getTagApiV1TagsTagIdGetResponseError;

export const getGetTagApiV1TagsTagIdGetUrl = (tagId: string) => {
  return `/api/v1/tags/${tagId}`;
};

export const getTagApiV1TagsTagIdGet = async (
  tagId: string,
  options?: RequestInit,
): Promise<getTagApiV1TagsTagIdGetResponse> => {
  return customFetch<getTagApiV1TagsTagIdGetResponse>(
    getGetTagApiV1TagsTagIdGetUrl(tagId),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetTagApiV1TagsTagIdGetQueryKey = (tagId: string) => {
  return [`/api/v1/tags/${tagId}`] as const;
};

export const getGetTagApiV1TagsTagIdGetQueryOptions = <
  TData = Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
  TError = HTTPValidationError,
>(
  tagId: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ?? getGetTagApiV1TagsTagIdGetQueryKey(tagId);

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

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

export type GetTagApiV1TagsTagIdGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>
>;
export type GetTagApiV1TagsTagIdGetQueryError = HTTPValidationError;

export function useGetTagApiV1TagsTagIdGet<
  TData = Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
  TError = HTTPValidationError,
>(
  tagId: string,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
          TError,
          Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetTagApiV1TagsTagIdGet<
  TData = Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
  TError = HTTPValidationError,
>(
  tagId: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
          TError,
          Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetTagApiV1TagsTagIdGet<
  TData = Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
  TError = HTTPValidationError,
>(
  tagId: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get Tag
 */

export function useGetTagApiV1TagsTagIdGet<
  TData = Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
  TError = HTTPValidationError,
>(
  tagId: string,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getTagApiV1TagsTagIdGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getGetTagApiV1TagsTagIdGetQueryOptions(tagId, options);

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

  return { ...query, queryKey: queryOptions.queryKey };
}

/**
 * Update a tag in the active organization.
 * @summary Update Tag
 */
export type updateTagApiV1TagsTagIdPatchResponse200 = {
  data: TagRead;
  status: 200;
};

export type updateTagApiV1TagsTagIdPatchResponse422 = {
  data: HTTPValidationError;
  status: 422;
};

export type updateTagApiV1TagsTagIdPatchResponseSuccess =
  updateTagApiV1TagsTagIdPatchResponse200 & {
    headers: Headers;
  };
export type updateTagApiV1TagsTagIdPatchResponseError =
  updateTagApiV1TagsTagIdPatchResponse422 & {
    headers: Headers;
  };

export type updateTagApiV1TagsTagIdPatchResponse =
  | updateTagApiV1TagsTagIdPatchResponseSuccess
  | updateTagApiV1TagsTagIdPatchResponseError;

export const getUpdateTagApiV1TagsTagIdPatchUrl = (tagId: string) => {
  return `/api/v1/tags/${tagId}`;
};

export const updateTagApiV1TagsTagIdPatch = async (
  tagId: string,
  tagUpdate: TagUpdate,
  options?: RequestInit,
): Promise<updateTagApiV1TagsTagIdPatchResponse> => {
  return customFetch<updateTagApiV1TagsTagIdPatchResponse>(
    getUpdateTagApiV1TagsTagIdPatchUrl(tagId),
    {
      ...options,
      method: "PATCH",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(tagUpdate),
    },
  );
};

export const getUpdateTagApiV1TagsTagIdPatchMutationOptions = <
  TError = HTTPValidationError,
  TContext = unknown,
>(options?: {
  mutation?: UseMutationOptions<
    Awaited<ReturnType<typeof updateTagApiV1TagsTagIdPatch>>,
    TError,
    { tagId: string; data: TagUpdate },
    TContext
  >;
  request?: SecondParameter<typeof customFetch>;
}): UseMutationOptions<
  Awaited<ReturnType<typeof updateTagApiV1TagsTagIdPatch>>,
  TError,
  { tagId: string; data: TagUpdate },
  TContext
> => {
  const mutationKey = ["updateTagApiV1TagsTagIdPatch"];
  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 updateTagApiV1TagsTagIdPatch>>,
    { tagId: string; data: TagUpdate }
  > = (props) => {
    const { tagId, data } = props ?? {};

    return updateTagApiV1TagsTagIdPatch(tagId, data, requestOptions);
  };

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

export type UpdateTagApiV1TagsTagIdPatchMutationResult = NonNullable<
  Awaited<ReturnType<typeof updateTagApiV1TagsTagIdPatch>>
>;
export type UpdateTagApiV1TagsTagIdPatchMutationBody = TagUpdate;
export type UpdateTagApiV1TagsTagIdPatchMutationError = HTTPValidationError;

/**
 * @summary Update Tag
 */
export const useUpdateTagApiV1TagsTagIdPatch = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof updateTagApiV1TagsTagIdPatch>>,
      TError,
      { tagId: string; data: TagUpdate },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof updateTagApiV1TagsTagIdPatch>>,
  TError,
  { tagId: string; data: TagUpdate },
  TContext
> => {
  return useMutation(
    getUpdateTagApiV1TagsTagIdPatchMutationOptions(options),
    queryClient,
  );
};
