/**
 * 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 {
  CloseIssueResponse,
  ForgejoIssueListResponse,
  ForgejoIssueRead,
  HTTPValidationError,
  ListIssuesApiV1ForgejoIssuesGetParams,
} from ".././model";

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

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

/**
 * List cached issues with optional filters.
 * @summary List Issues
 */
export type listIssuesApiV1ForgejoIssuesGetResponse200 = {
  data: ForgejoIssueListResponse;
  status: 200;
};

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

export type listIssuesApiV1ForgejoIssuesGetResponseSuccess =
  listIssuesApiV1ForgejoIssuesGetResponse200 & {
    headers: Headers;
  };
export type listIssuesApiV1ForgejoIssuesGetResponseError =
  listIssuesApiV1ForgejoIssuesGetResponse422 & {
    headers: Headers;
  };

export type listIssuesApiV1ForgejoIssuesGetResponse =
  | listIssuesApiV1ForgejoIssuesGetResponseSuccess
  | listIssuesApiV1ForgejoIssuesGetResponseError;

export const getListIssuesApiV1ForgejoIssuesGetUrl = (
  params?: ListIssuesApiV1ForgejoIssuesGetParams,
) => {
  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/forgejo/issues?${stringifiedParams}`
    : `/api/v1/forgejo/issues`;
};

export const listIssuesApiV1ForgejoIssuesGet = async (
  params?: ListIssuesApiV1ForgejoIssuesGetParams,
  options?: RequestInit,
): Promise<listIssuesApiV1ForgejoIssuesGetResponse> => {
  return customFetch<listIssuesApiV1ForgejoIssuesGetResponse>(
    getListIssuesApiV1ForgejoIssuesGetUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getListIssuesApiV1ForgejoIssuesGetQueryKey = (
  params?: ListIssuesApiV1ForgejoIssuesGetParams,
) => {
  return [`/api/v1/forgejo/issues`, ...(params ? [params] : [])] as const;
};

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

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

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

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

export type ListIssuesApiV1ForgejoIssuesGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof listIssuesApiV1ForgejoIssuesGet>>
>;
export type ListIssuesApiV1ForgejoIssuesGetQueryError = HTTPValidationError;

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

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

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

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

/**
 * Get one cached issue by ID.
 * @summary Get Issue
 */
export type getIssueApiV1ForgejoIssuesIssueIdGetResponse200 = {
  data: ForgejoIssueRead;
  status: 200;
};

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

export type getIssueApiV1ForgejoIssuesIssueIdGetResponseSuccess =
  getIssueApiV1ForgejoIssuesIssueIdGetResponse200 & {
    headers: Headers;
  };
export type getIssueApiV1ForgejoIssuesIssueIdGetResponseError =
  getIssueApiV1ForgejoIssuesIssueIdGetResponse422 & {
    headers: Headers;
  };

export type getIssueApiV1ForgejoIssuesIssueIdGetResponse =
  | getIssueApiV1ForgejoIssuesIssueIdGetResponseSuccess
  | getIssueApiV1ForgejoIssuesIssueIdGetResponseError;

export const getGetIssueApiV1ForgejoIssuesIssueIdGetUrl = (issueId: string) => {
  return `/api/v1/forgejo/issues/${issueId}`;
};

export const getIssueApiV1ForgejoIssuesIssueIdGet = async (
  issueId: string,
  options?: RequestInit,
): Promise<getIssueApiV1ForgejoIssuesIssueIdGetResponse> => {
  return customFetch<getIssueApiV1ForgejoIssuesIssueIdGetResponse>(
    getGetIssueApiV1ForgejoIssuesIssueIdGetUrl(issueId),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetIssueApiV1ForgejoIssuesIssueIdGetQueryKey = (
  issueId: string,
) => {
  return [`/api/v1/forgejo/issues/${issueId}`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ??
    getGetIssueApiV1ForgejoIssuesIssueIdGetQueryKey(issueId);

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

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

export type GetIssueApiV1ForgejoIssuesIssueIdGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof getIssueApiV1ForgejoIssuesIssueIdGet>>
>;
export type GetIssueApiV1ForgejoIssuesIssueIdGetQueryError =
  HTTPValidationError;

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

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

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

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

/**
 * Close a Forgejo issue by its local ID. The user must have write access to the board that the issue's repository is linked to.
 * @summary Close a Forgejo issue (human user)
 */
export type closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse200 = {
  data: CloseIssueResponse;
  status: 200;
};

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

export type closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse404 = {
  data: void;
  status: 404;
};

export type closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse409 = {
  data: void;
  status: 409;
};

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

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

export type closeIssueApiV1ForgejoIssuesIssueIdClosePostResponseSuccess =
  closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse200 & {
    headers: Headers;
  };
export type closeIssueApiV1ForgejoIssuesIssueIdClosePostResponseError = (
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse403
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse404
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse409
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse422
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse502
) & {
  headers: Headers;
};

export type closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse =
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponseSuccess
  | closeIssueApiV1ForgejoIssuesIssueIdClosePostResponseError;

export const getCloseIssueApiV1ForgejoIssuesIssueIdClosePostUrl = (
  issueId: string,
) => {
  return `/api/v1/forgejo/issues/${issueId}/close`;
};

export const closeIssueApiV1ForgejoIssuesIssueIdClosePost = async (
  issueId: string,
  options?: RequestInit,
): Promise<closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse> => {
  return customFetch<closeIssueApiV1ForgejoIssuesIssueIdClosePostResponse>(
    getCloseIssueApiV1ForgejoIssuesIssueIdClosePostUrl(issueId),
    {
      ...options,
      method: "POST",
    },
  );
};

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

    return closeIssueApiV1ForgejoIssuesIssueIdClosePost(
      issueId,
      requestOptions,
    );
  };

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

export type CloseIssueApiV1ForgejoIssuesIssueIdClosePostMutationResult =
  NonNullable<
    Awaited<ReturnType<typeof closeIssueApiV1ForgejoIssuesIssueIdClosePost>>
  >;

export type CloseIssueApiV1ForgejoIssuesIssueIdClosePostMutationError =
  void | HTTPValidationError;

/**
 * @summary Close a Forgejo issue (human user)
 */
export const useCloseIssueApiV1ForgejoIssuesIssueIdClosePost = <
  TError = void | HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof closeIssueApiV1ForgejoIssuesIssueIdClosePost>>,
      TError,
      { issueId: string },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof closeIssueApiV1ForgejoIssuesIssueIdClosePost>>,
  TError,
  { issueId: string },
  TContext
> => {
  return useMutation(
    getCloseIssueApiV1ForgejoIssuesIssueIdClosePostMutationOptions(options),
    queryClient,
  );
};
