/**
 * 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 {
  BoardRepositoryLinkCreate,
  BoardRepositoryLinkDeleteResponse,
  BoardRepositoryLinkRead,
  BoardRepositoryLinkResponse,
  HTTPValidationError,
} from ".././model";

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

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

/**
 * List repositories linked to a board.
 * @summary List Board Repositories
 */
export type listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponse200 =
  {
    data: BoardRepositoryLinkRead[];
    status: 200;
  };

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

export type listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponseSuccess =
  listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponse200 & {
    headers: Headers;
  };
export type listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponseError =
  listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponse422 & {
    headers: Headers;
  };

export type listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponse =

    | listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponseSuccess
    | listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponseError;

export const getListBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetUrl =
  (boardId: string) => {
    return `/api/v1/boards/${boardId}/forgejo/repositories`;
  };

export const listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGet =
  async (
    boardId: string,
    options?: RequestInit,
  ): Promise<listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponse> => {
    return customFetch<listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetResponse>(
      getListBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetUrl(
        boardId,
      ),
      {
        ...options,
        method: "GET",
      },
    );
  };

export const getListBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetQueryKey =
  (boardId: string) => {
    return [`/api/v1/boards/${boardId}/forgejo/repositories`] as const;
  };

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

    const queryKey =
      queryOptions?.queryKey ??
      getListBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetQueryKey(
        boardId,
      );

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

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

export type ListBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetQueryResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof listBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGet
      >
    >
  >;
export type ListBoardRepositoriesApiV1BoardsBoardIdForgejoRepositoriesGetQueryError =
  HTTPValidationError;

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

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

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

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

/**
 * Link a Forgejo repository to a board.
 * @summary Link Repository To Board
 */
export type linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponse200 =
  {
    data: BoardRepositoryLinkResponse;
    status: 200;
  };

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

export type linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponseSuccess =
  linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponse200 & {
    headers: Headers;
  };
export type linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponseError =
  linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponse422 & {
    headers: Headers;
  };

export type linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponse =

    | linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponseSuccess
    | linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponseError;

export const getLinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostUrl =
  (boardId: string) => {
    return `/api/v1/boards/${boardId}/forgejo/repositories`;
  };

export const linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPost =
  async (
    boardId: string,
    boardRepositoryLinkCreate: BoardRepositoryLinkCreate,
    options?: RequestInit,
  ): Promise<linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponse> => {
    return customFetch<linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostResponse>(
      getLinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostUrl(
        boardId,
      ),
      {
        ...options,
        method: "POST",
        headers: { "Content-Type": "application/json", ...options?.headers },
        body: JSON.stringify(boardRepositoryLinkCreate),
      },
    );
  };

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

      return linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPost(
        boardId,
        data,
        requestOptions,
      );
    };

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

export type LinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPost
      >
    >
  >;
export type LinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostMutationBody =
  BoardRepositoryLinkCreate;
export type LinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostMutationError =
  HTTPValidationError;

/**
 * @summary Link Repository To Board
 */
export const useLinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPost =
  <TError = HTTPValidationError, TContext = unknown>(
    options?: {
      mutation?: UseMutationOptions<
        Awaited<
          ReturnType<
            typeof linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPost
          >
        >,
        TError,
        { boardId: string; data: BoardRepositoryLinkCreate },
        TContext
      >;
      request?: SecondParameter<typeof customFetch>;
    },
    queryClient?: QueryClient,
  ): UseMutationResult<
    Awaited<
      ReturnType<
        typeof linkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPost
      >
    >,
    TError,
    { boardId: string; data: BoardRepositoryLinkCreate },
    TContext
  > => {
    return useMutation(
      getLinkRepositoryToBoardApiV1BoardsBoardIdForgejoRepositoriesPostMutationOptions(
        options,
      ),
      queryClient,
    );
  };
/**
 * Remove a repository link from a board.
 * @summary Unlink Repository From Board
 */
export type unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponse200 =
  {
    data: BoardRepositoryLinkDeleteResponse;
    status: 200;
  };

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

export type unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponseSuccess =
  unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponse200 & {
    headers: Headers;
  };
export type unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponseError =
  unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponse422 & {
    headers: Headers;
  };

export type unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponse =

    | unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponseSuccess
    | unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponseError;

export const getUnlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteUrl =
  (boardId: string, repositoryId: string) => {
    return `/api/v1/boards/${boardId}/forgejo/repositories/${repositoryId}`;
  };

export const unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDelete =
  async (
    boardId: string,
    repositoryId: string,
    options?: RequestInit,
  ): Promise<unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponse> => {
    return customFetch<unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteResponse>(
      getUnlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteUrl(
        boardId,
        repositoryId,
      ),
      {
        ...options,
        method: "DELETE",
      },
    );
  };

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

      return unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDelete(
        boardId,
        repositoryId,
        requestOptions,
      );
    };

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

export type UnlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDelete
      >
    >
  >;

export type UnlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteMutationError =
  HTTPValidationError;

/**
 * @summary Unlink Repository From Board
 */
export const useUnlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDelete =
  <TError = HTTPValidationError, TContext = unknown>(
    options?: {
      mutation?: UseMutationOptions<
        Awaited<
          ReturnType<
            typeof unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDelete
          >
        >,
        TError,
        { boardId: string; repositoryId: string },
        TContext
      >;
      request?: SecondParameter<typeof customFetch>;
    },
    queryClient?: QueryClient,
  ): UseMutationResult<
    Awaited<
      ReturnType<
        typeof unlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDelete
      >
    >,
    TError,
    { boardId: string; repositoryId: string },
    TContext
  > => {
    return useMutation(
      getUnlinkRepositoryFromBoardApiV1BoardsBoardIdForgejoRepositoriesRepositoryIdDeleteMutationOptions(
        options,
      ),
      queryClient,
    );
  };
