/**
 * Generated by orval v8.3.0 🍺
 * Do not edit manually.
 * Mission Control API
 * OpenAPI spec version: 0.1.0
 */
import { useMutation } from "@tanstack/react-query";
import type {
  MutationFunction,
  QueryClient,
  UseMutationOptions,
  UseMutationResult,
} from "@tanstack/react-query";

import type {
  ForgejoWebhookIngestResponse,
  HTTPValidationError,
} from ".././model";

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

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

/**
 * Receive Forgejo issue webhooks and update cached issue records.
 * @summary Ingest Forgejo Webhook
 */
export type ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponse202 =
  {
    data: ForgejoWebhookIngestResponse;
    status: 202;
  };

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

export type ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponseSuccess =
  ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponse202 & {
    headers: Headers;
  };
export type ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponseError =
  ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponse422 & {
    headers: Headers;
  };

export type ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponse =
  | ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponseSuccess
  | ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponseError;

export const getIngestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostUrl = (
  repositoryId: string,
) => {
  return `/api/v1/forgejo/webhooks/${repositoryId}`;
};

export const ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPost = async (
  repositoryId: string,
  options?: RequestInit,
): Promise<ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponse> => {
  return customFetch<ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostResponse>(
    getIngestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostUrl(
      repositoryId,
    ),
    {
      ...options,
      method: "POST",
    },
  );
};

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

      return ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPost(
        repositoryId,
        requestOptions,
      );
    };

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

export type IngestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPost
      >
    >
  >;

export type IngestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostMutationError =
  HTTPValidationError;

/**
 * @summary Ingest Forgejo Webhook
 */
export const useIngestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPost = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<
          typeof ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPost
        >
      >,
      TError,
      { repositoryId: string },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<
    ReturnType<typeof ingestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPost>
  >,
  TError,
  { repositoryId: string },
  TContext
> => {
  return useMutation(
    getIngestForgejoWebhookApiV1ForgejoWebhooksRepositoryIdPostMutationOptions(
      options,
    ),
    queryClient,
  );
};
