/**
 * Generated by orval v8.3.0 🍺
 * Do not edit manually.
 * Mission Control API
 * OpenAPI spec version: 0.1.0
 */
import { useQuery } from "@tanstack/react-query";
import type {
  DataTag,
  DefinedInitialDataOptions,
  DefinedUseQueryResult,
  QueryClient,
  QueryFunction,
  QueryKey,
  UndefinedInitialDataOptions,
  UseQueryOptions,
  UseQueryResult,
} from "@tanstack/react-query";

import type {
  GetForgejoHeatmapApiV1ForgejoHeatmapGetParams,
  GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  HTTPValidationError,
  HeatmapResponse,
  MetricsResponse,
} from ".././model";

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

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

/**
 * Get aggregated metrics for Forgejo issues across linked repositories. Supports filtering by organization_id, board_id, or repository_id. Empty scope returns zeroed metrics.
 * @summary Forgejo issue tracking metrics
 */
export type getForgejoMetricsApiV1ForgejoMetricsGetResponse200 = {
  data: MetricsResponse;
  status: 200;
};

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

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

export type getForgejoMetricsApiV1ForgejoMetricsGetResponseSuccess =
  getForgejoMetricsApiV1ForgejoMetricsGetResponse200 & {
    headers: Headers;
  };
export type getForgejoMetricsApiV1ForgejoMetricsGetResponseError = (
  | getForgejoMetricsApiV1ForgejoMetricsGetResponse403
  | getForgejoMetricsApiV1ForgejoMetricsGetResponse422
) & {
  headers: Headers;
};

export type getForgejoMetricsApiV1ForgejoMetricsGetResponse =
  | getForgejoMetricsApiV1ForgejoMetricsGetResponseSuccess
  | getForgejoMetricsApiV1ForgejoMetricsGetResponseError;

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

export const getForgejoMetricsApiV1ForgejoMetricsGet = async (
  params?: GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  options?: RequestInit,
): Promise<getForgejoMetricsApiV1ForgejoMetricsGetResponse> => {
  return customFetch<getForgejoMetricsApiV1ForgejoMetricsGetResponse>(
    getGetForgejoMetricsApiV1ForgejoMetricsGetUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetForgejoMetricsApiV1ForgejoMetricsGetQueryKey = (
  params?: GetForgejoMetricsApiV1ForgejoMetricsGetParams,
) => {
  return [`/api/v1/forgejo/metrics`, ...(params ? [params] : [])] as const;
};

export const getGetForgejoMetricsApiV1ForgejoMetricsGetQueryOptions = <
  TData = Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
  TError = void | HTTPValidationError,
>(
  params?: GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

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

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

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

export type GetForgejoMetricsApiV1ForgejoMetricsGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>
>;
export type GetForgejoMetricsApiV1ForgejoMetricsGetQueryError =
  void | HTTPValidationError;

export function useGetForgejoMetricsApiV1ForgejoMetricsGet<
  TData = Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
  TError = void | HTTPValidationError,
>(
  params: undefined | GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
          TError,
          Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetForgejoMetricsApiV1ForgejoMetricsGet<
  TData = Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
  TError = void | HTTPValidationError,
>(
  params?: GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
          TError,
          Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetForgejoMetricsApiV1ForgejoMetricsGet<
  TData = Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
  TError = void | HTTPValidationError,
>(
  params?: GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Forgejo issue tracking metrics
 */

export function useGetForgejoMetricsApiV1ForgejoMetricsGet<
  TData = Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
  TError = void | HTTPValidationError,
>(
  params?: GetForgejoMetricsApiV1ForgejoMetricsGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoMetricsApiV1ForgejoMetricsGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getGetForgejoMetricsApiV1ForgejoMetricsGetQueryOptions(
    params,
    options,
  );

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

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

/**
 * Daily issue open+close event counts for the last 365 days, scoped to the caller's organisation.
 * @summary Forgejo issue activity heatmap
 */
export type getForgejoHeatmapApiV1ForgejoHeatmapGetResponse200 = {
  data: HeatmapResponse;
  status: 200;
};

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

export type getForgejoHeatmapApiV1ForgejoHeatmapGetResponseSuccess =
  getForgejoHeatmapApiV1ForgejoHeatmapGetResponse200 & {
    headers: Headers;
  };
export type getForgejoHeatmapApiV1ForgejoHeatmapGetResponseError =
  getForgejoHeatmapApiV1ForgejoHeatmapGetResponse422 & {
    headers: Headers;
  };

export type getForgejoHeatmapApiV1ForgejoHeatmapGetResponse =
  | getForgejoHeatmapApiV1ForgejoHeatmapGetResponseSuccess
  | getForgejoHeatmapApiV1ForgejoHeatmapGetResponseError;

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

export const getForgejoHeatmapApiV1ForgejoHeatmapGet = async (
  params?: GetForgejoHeatmapApiV1ForgejoHeatmapGetParams,
  options?: RequestInit,
): Promise<getForgejoHeatmapApiV1ForgejoHeatmapGetResponse> => {
  return customFetch<getForgejoHeatmapApiV1ForgejoHeatmapGetResponse>(
    getGetForgejoHeatmapApiV1ForgejoHeatmapGetUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetForgejoHeatmapApiV1ForgejoHeatmapGetQueryKey = (
  params?: GetForgejoHeatmapApiV1ForgejoHeatmapGetParams,
) => {
  return [`/api/v1/forgejo/heatmap`, ...(params ? [params] : [])] as const;
};

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

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

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

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

export type GetForgejoHeatmapApiV1ForgejoHeatmapGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>
>;
export type GetForgejoHeatmapApiV1ForgejoHeatmapGetQueryError =
  HTTPValidationError;

export function useGetForgejoHeatmapApiV1ForgejoHeatmapGet<
  TData = Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
  TError = HTTPValidationError,
>(
  params: undefined | GetForgejoHeatmapApiV1ForgejoHeatmapGetParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
          TError,
          Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetForgejoHeatmapApiV1ForgejoHeatmapGet<
  TData = Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
  TError = HTTPValidationError,
>(
  params?: GetForgejoHeatmapApiV1ForgejoHeatmapGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
          TError,
          Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetForgejoHeatmapApiV1ForgejoHeatmapGet<
  TData = Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
  TError = HTTPValidationError,
>(
  params?: GetForgejoHeatmapApiV1ForgejoHeatmapGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof getForgejoHeatmapApiV1ForgejoHeatmapGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Forgejo issue activity heatmap
 */

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

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

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