/**
 * 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 {
  ForgejoConnectionCreate,
  ForgejoConnectionRead,
  ForgejoConnectionTestRequest,
  ForgejoConnectionTestResponse,
  ForgejoConnectionUpdate,
  ForgejoConnectionValidationResponse,
  HTTPValidationError,
  ListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGet200Item,
  OkResponse,
} from ".././model";

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

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

/**
 * List Forgejo connections for the caller's organization.
 * @summary List Connections
 */
export type listConnectionsApiV1ForgejoConnectionsGetResponse200 = {
  data: ForgejoConnectionRead[];
  status: 200;
};

export type listConnectionsApiV1ForgejoConnectionsGetResponseSuccess =
  listConnectionsApiV1ForgejoConnectionsGetResponse200 & {
    headers: Headers;
  };
export type listConnectionsApiV1ForgejoConnectionsGetResponse =
  listConnectionsApiV1ForgejoConnectionsGetResponseSuccess;

export const getListConnectionsApiV1ForgejoConnectionsGetUrl = () => {
  return `/api/v1/forgejo/connections`;
};

export const listConnectionsApiV1ForgejoConnectionsGet = async (
  options?: RequestInit,
): Promise<listConnectionsApiV1ForgejoConnectionsGetResponse> => {
  return customFetch<listConnectionsApiV1ForgejoConnectionsGetResponse>(
    getListConnectionsApiV1ForgejoConnectionsGetUrl(),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getListConnectionsApiV1ForgejoConnectionsGetQueryKey = () => {
  return [`/api/v1/forgejo/connections`] as const;
};

export const getListConnectionsApiV1ForgejoConnectionsGetQueryOptions = <
  TData = Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
  TError = unknown,
>(options?: {
  query?: Partial<
    UseQueryOptions<
      Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
      TError,
      TData
    >
  >;
  request?: SecondParameter<typeof customFetch>;
}) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type ListConnectionsApiV1ForgejoConnectionsGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>
>;
export type ListConnectionsApiV1ForgejoConnectionsGetQueryError = unknown;

export function useListConnectionsApiV1ForgejoConnectionsGet<
  TData = Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
  TError = unknown,
>(
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
          TError,
          Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useListConnectionsApiV1ForgejoConnectionsGet<
  TData = Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
          TError,
          Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useListConnectionsApiV1ForgejoConnectionsGet<
  TData = Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary List Connections
 */

export function useListConnectionsApiV1ForgejoConnectionsGet<
  TData = Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
  TError = unknown,
>(
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof listConnectionsApiV1ForgejoConnectionsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions =
    getListConnectionsApiV1ForgejoConnectionsGetQueryOptions(options);

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

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

/**
 * Create a Forgejo connection for the caller's organization.
 * @summary Create Connection
 */
export type createConnectionApiV1ForgejoConnectionsPostResponse200 = {
  data: ForgejoConnectionRead;
  status: 200;
};

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

export type createConnectionApiV1ForgejoConnectionsPostResponseSuccess =
  createConnectionApiV1ForgejoConnectionsPostResponse200 & {
    headers: Headers;
  };
export type createConnectionApiV1ForgejoConnectionsPostResponseError =
  createConnectionApiV1ForgejoConnectionsPostResponse422 & {
    headers: Headers;
  };

export type createConnectionApiV1ForgejoConnectionsPostResponse =
  | createConnectionApiV1ForgejoConnectionsPostResponseSuccess
  | createConnectionApiV1ForgejoConnectionsPostResponseError;

export const getCreateConnectionApiV1ForgejoConnectionsPostUrl = () => {
  return `/api/v1/forgejo/connections`;
};

export const createConnectionApiV1ForgejoConnectionsPost = async (
  forgejoConnectionCreate: ForgejoConnectionCreate,
  options?: RequestInit,
): Promise<createConnectionApiV1ForgejoConnectionsPostResponse> => {
  return customFetch<createConnectionApiV1ForgejoConnectionsPostResponse>(
    getCreateConnectionApiV1ForgejoConnectionsPostUrl(),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(forgejoConnectionCreate),
    },
  );
};

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

    return createConnectionApiV1ForgejoConnectionsPost(data, requestOptions);
  };

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

export type CreateConnectionApiV1ForgejoConnectionsPostMutationResult =
  NonNullable<
    Awaited<ReturnType<typeof createConnectionApiV1ForgejoConnectionsPost>>
  >;
export type CreateConnectionApiV1ForgejoConnectionsPostMutationBody =
  ForgejoConnectionCreate;
export type CreateConnectionApiV1ForgejoConnectionsPostMutationError =
  HTTPValidationError;

/**
 * @summary Create Connection
 */
export const useCreateConnectionApiV1ForgejoConnectionsPost = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof createConnectionApiV1ForgejoConnectionsPost>>,
      TError,
      { data: ForgejoConnectionCreate },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof createConnectionApiV1ForgejoConnectionsPost>>,
  TError,
  { data: ForgejoConnectionCreate },
  TContext
> => {
  return useMutation(
    getCreateConnectionApiV1ForgejoConnectionsPostMutationOptions(options),
    queryClient,
  );
};
/**
 * Return one Forgejo connection by id for the caller's organization.
 * @summary Get Connection
 */
export type getConnectionApiV1ForgejoConnectionsConnectionIdGetResponse200 = {
  data: ForgejoConnectionRead;
  status: 200;
};

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

export type getConnectionApiV1ForgejoConnectionsConnectionIdGetResponseSuccess =
  getConnectionApiV1ForgejoConnectionsConnectionIdGetResponse200 & {
    headers: Headers;
  };
export type getConnectionApiV1ForgejoConnectionsConnectionIdGetResponseError =
  getConnectionApiV1ForgejoConnectionsConnectionIdGetResponse422 & {
    headers: Headers;
  };

export type getConnectionApiV1ForgejoConnectionsConnectionIdGetResponse =
  | getConnectionApiV1ForgejoConnectionsConnectionIdGetResponseSuccess
  | getConnectionApiV1ForgejoConnectionsConnectionIdGetResponseError;

export const getGetConnectionApiV1ForgejoConnectionsConnectionIdGetUrl = (
  connectionId: string,
) => {
  return `/api/v1/forgejo/connections/${connectionId}`;
};

export const getConnectionApiV1ForgejoConnectionsConnectionIdGet = async (
  connectionId: string,
  options?: RequestInit,
): Promise<getConnectionApiV1ForgejoConnectionsConnectionIdGetResponse> => {
  return customFetch<getConnectionApiV1ForgejoConnectionsConnectionIdGetResponse>(
    getGetConnectionApiV1ForgejoConnectionsConnectionIdGetUrl(connectionId),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetConnectionApiV1ForgejoConnectionsConnectionIdGetQueryKey = (
  connectionId: string,
) => {
  return [`/api/v1/forgejo/connections/${connectionId}`] as const;
};

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

    const queryKey =
      queryOptions?.queryKey ??
      getGetConnectionApiV1ForgejoConnectionsConnectionIdGetQueryKey(
        connectionId,
      );

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

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

export type GetConnectionApiV1ForgejoConnectionsConnectionIdGetQueryResult =
  NonNullable<
    Awaited<
      ReturnType<typeof getConnectionApiV1ForgejoConnectionsConnectionIdGet>
    >
  >;
export type GetConnectionApiV1ForgejoConnectionsConnectionIdGetQueryError =
  HTTPValidationError;

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

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

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

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

/**
 * Patch a Forgejo connection for the caller's organization.
 * @summary Update Connection
 */
export type updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponse200 =
  {
    data: ForgejoConnectionRead;
    status: 200;
  };

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

export type updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponseSuccess =
  updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponse200 & {
    headers: Headers;
  };
export type updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponseError =
  updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponse422 & {
    headers: Headers;
  };

export type updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponse =
  | updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponseSuccess
  | updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponseError;

export const getUpdateConnectionApiV1ForgejoConnectionsConnectionIdPatchUrl = (
  connectionId: string,
) => {
  return `/api/v1/forgejo/connections/${connectionId}`;
};

export const updateConnectionApiV1ForgejoConnectionsConnectionIdPatch = async (
  connectionId: string,
  forgejoConnectionUpdate: ForgejoConnectionUpdate,
  options?: RequestInit,
): Promise<updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponse> => {
  return customFetch<updateConnectionApiV1ForgejoConnectionsConnectionIdPatchResponse>(
    getUpdateConnectionApiV1ForgejoConnectionsConnectionIdPatchUrl(
      connectionId,
    ),
    {
      ...options,
      method: "PATCH",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(forgejoConnectionUpdate),
    },
  );
};

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

      return updateConnectionApiV1ForgejoConnectionsConnectionIdPatch(
        connectionId,
        data,
        requestOptions,
      );
    };

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

export type UpdateConnectionApiV1ForgejoConnectionsConnectionIdPatchMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof updateConnectionApiV1ForgejoConnectionsConnectionIdPatch
      >
    >
  >;
export type UpdateConnectionApiV1ForgejoConnectionsConnectionIdPatchMutationBody =
  ForgejoConnectionUpdate;
export type UpdateConnectionApiV1ForgejoConnectionsConnectionIdPatchMutationError =
  HTTPValidationError;

/**
 * @summary Update Connection
 */
export const useUpdateConnectionApiV1ForgejoConnectionsConnectionIdPatch = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<
          typeof updateConnectionApiV1ForgejoConnectionsConnectionIdPatch
        >
      >,
      TError,
      { connectionId: string; data: ForgejoConnectionUpdate },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<
    ReturnType<typeof updateConnectionApiV1ForgejoConnectionsConnectionIdPatch>
  >,
  TError,
  { connectionId: string; data: ForgejoConnectionUpdate },
  TContext
> => {
  return useMutation(
    getUpdateConnectionApiV1ForgejoConnectionsConnectionIdPatchMutationOptions(
      options,
    ),
    queryClient,
  );
};
/**
 * Delete a Forgejo connection for the caller's organization.
 * @summary Delete Connection
 */
export type deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponse200 =
  {
    data: OkResponse;
    status: 200;
  };

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

export type deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponseSuccess =
  deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponse200 & {
    headers: Headers;
  };
export type deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponseError =
  deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponse422 & {
    headers: Headers;
  };

export type deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponse =
  | deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponseSuccess
  | deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponseError;

export const getDeleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteUrl = (
  connectionId: string,
) => {
  return `/api/v1/forgejo/connections/${connectionId}`;
};

export const deleteConnectionApiV1ForgejoConnectionsConnectionIdDelete = async (
  connectionId: string,
  options?: RequestInit,
): Promise<deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponse> => {
  return customFetch<deleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteResponse>(
    getDeleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteUrl(
      connectionId,
    ),
    {
      ...options,
      method: "DELETE",
    },
  );
};

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

      return deleteConnectionApiV1ForgejoConnectionsConnectionIdDelete(
        connectionId,
        requestOptions,
      );
    };

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

export type DeleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof deleteConnectionApiV1ForgejoConnectionsConnectionIdDelete
      >
    >
  >;

export type DeleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteMutationError =
  HTTPValidationError;

/**
 * @summary Delete Connection
 */
export const useDeleteConnectionApiV1ForgejoConnectionsConnectionIdDelete = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<
          typeof deleteConnectionApiV1ForgejoConnectionsConnectionIdDelete
        >
      >,
      TError,
      { connectionId: string },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<
    ReturnType<typeof deleteConnectionApiV1ForgejoConnectionsConnectionIdDelete>
  >,
  TError,
  { connectionId: string },
  TContext
> => {
  return useMutation(
    getDeleteConnectionApiV1ForgejoConnectionsConnectionIdDeleteMutationOptions(
      options,
    ),
    queryClient,
  );
};
/**
 * Validate a base URL and token against a Forgejo instance without saving a connection record.
 * @summary Test Connection Before Saving
 */
export type testConnectionApiV1ForgejoConnectionsTestPostResponse200 = {
  data: ForgejoConnectionTestResponse;
  status: 200;
};

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

export type testConnectionApiV1ForgejoConnectionsTestPostResponseSuccess =
  testConnectionApiV1ForgejoConnectionsTestPostResponse200 & {
    headers: Headers;
  };
export type testConnectionApiV1ForgejoConnectionsTestPostResponseError =
  testConnectionApiV1ForgejoConnectionsTestPostResponse422 & {
    headers: Headers;
  };

export type testConnectionApiV1ForgejoConnectionsTestPostResponse =
  | testConnectionApiV1ForgejoConnectionsTestPostResponseSuccess
  | testConnectionApiV1ForgejoConnectionsTestPostResponseError;

export const getTestConnectionApiV1ForgejoConnectionsTestPostUrl = () => {
  return `/api/v1/forgejo/connections/test`;
};

export const testConnectionApiV1ForgejoConnectionsTestPost = async (
  forgejoConnectionTestRequest: ForgejoConnectionTestRequest,
  options?: RequestInit,
): Promise<testConnectionApiV1ForgejoConnectionsTestPostResponse> => {
  return customFetch<testConnectionApiV1ForgejoConnectionsTestPostResponse>(
    getTestConnectionApiV1ForgejoConnectionsTestPostUrl(),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(forgejoConnectionTestRequest),
    },
  );
};

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

    return testConnectionApiV1ForgejoConnectionsTestPost(data, requestOptions);
  };

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

export type TestConnectionApiV1ForgejoConnectionsTestPostMutationResult =
  NonNullable<
    Awaited<ReturnType<typeof testConnectionApiV1ForgejoConnectionsTestPost>>
  >;
export type TestConnectionApiV1ForgejoConnectionsTestPostMutationBody =
  ForgejoConnectionTestRequest;
export type TestConnectionApiV1ForgejoConnectionsTestPostMutationError =
  HTTPValidationError;

/**
 * @summary Test Connection Before Saving
 */
export const useTestConnectionApiV1ForgejoConnectionsTestPost = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<ReturnType<typeof testConnectionApiV1ForgejoConnectionsTestPost>>,
      TError,
      { data: ForgejoConnectionTestRequest },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<ReturnType<typeof testConnectionApiV1ForgejoConnectionsTestPost>>,
  TError,
  { data: ForgejoConnectionTestRequest },
  TContext
> => {
  return useMutation(
    getTestConnectionApiV1ForgejoConnectionsTestPostMutationOptions(options),
    queryClient,
  );
};
/**
 * Return repositories the connection token can access on the Forgejo instance.
 * @summary List Available Repositories
 */
export type listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponse200 =
  {
    data: ListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGet200Item[];
    status: 200;
  };

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

export type listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponseSuccess =
  listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponse200 & {
    headers: Headers;
  };
export type listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponseError =
  listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponse422 & {
    headers: Headers;
  };

export type listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponse =

    | listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponseSuccess
    | listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponseError;

export const getListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetUrl =
  (connectionId: string) => {
    return `/api/v1/forgejo/connections/${connectionId}/repos`;
  };

export const listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGet =
  async (
    connectionId: string,
    options?: RequestInit,
  ): Promise<listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponse> => {
    return customFetch<listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetResponse>(
      getListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetUrl(
        connectionId,
      ),
      {
        ...options,
        method: "GET",
      },
    );
  };

export const getListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetQueryKey =
  (connectionId: string) => {
    return [`/api/v1/forgejo/connections/${connectionId}/repos`] as const;
  };

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

    const queryKey =
      queryOptions?.queryKey ??
      getListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetQueryKey(
        connectionId,
      );

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

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

export type ListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetQueryResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof listConnectionReposApiV1ForgejoConnectionsConnectionIdReposGet
      >
    >
  >;
export type ListConnectionReposApiV1ForgejoConnectionsConnectionIdReposGetQueryError =
  HTTPValidationError;

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

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

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

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

/**
 * Test if a Forgejo connection can authenticate and access the API.
 * @summary Validate Forgejo Connection
 */
export type validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponse200 =
  {
    data: ForgejoConnectionValidationResponse;
    status: 200;
  };

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

export type validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponseSuccess =
  validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponse200 & {
    headers: Headers;
  };
export type validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponseError =
  validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponse422 & {
    headers: Headers;
  };

export type validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponse =

    | validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponseSuccess
    | validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponseError;

export const getValidateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostUrl =
  (connectionId: string) => {
    return `/api/v1/forgejo/connections/${connectionId}/validate`;
  };

export const validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePost =
  async (
    connectionId: string,
    options?: RequestInit,
  ): Promise<validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponse> => {
    return customFetch<validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostResponse>(
      getValidateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostUrl(
        connectionId,
      ),
      {
        ...options,
        method: "POST",
      },
    );
  };

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

      return validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePost(
        connectionId,
        requestOptions,
      );
    };

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

export type ValidateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePost
      >
    >
  >;

export type ValidateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostMutationError =
  HTTPValidationError;

/**
 * @summary Validate Forgejo Connection
 */
export const useValidateConnectionApiV1ForgejoConnectionsConnectionIdValidatePost =
  <TError = HTTPValidationError, TContext = unknown>(
    options?: {
      mutation?: UseMutationOptions<
        Awaited<
          ReturnType<
            typeof validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePost
          >
        >,
        TError,
        { connectionId: string },
        TContext
      >;
      request?: SecondParameter<typeof customFetch>;
    },
    queryClient?: QueryClient,
  ): UseMutationResult<
    Awaited<
      ReturnType<
        typeof validateConnectionApiV1ForgejoConnectionsConnectionIdValidatePost
      >
    >,
    TError,
    { connectionId: string },
    TContext
  > => {
    return useMutation(
      getValidateConnectionApiV1ForgejoConnectionsConnectionIdValidatePostMutationOptions(
        options,
      ),
      queryClient,
    );
  };
