/**
 * 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 {
  DashboardMetrics,
  DashboardMetricsApiV1MetricsDashboardGetParams,
  HTTPValidationError,
} from ".././model";

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

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

/**
 * Return dashboard KPIs and time-series data for accessible boards.
 * @summary Dashboard Metrics
 */
export type dashboardMetricsApiV1MetricsDashboardGetResponse200 = {
  data: DashboardMetrics;
  status: 200;
};

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

export type dashboardMetricsApiV1MetricsDashboardGetResponseSuccess =
  dashboardMetricsApiV1MetricsDashboardGetResponse200 & {
    headers: Headers;
  };
export type dashboardMetricsApiV1MetricsDashboardGetResponseError =
  dashboardMetricsApiV1MetricsDashboardGetResponse422 & {
    headers: Headers;
  };

export type dashboardMetricsApiV1MetricsDashboardGetResponse =
  | dashboardMetricsApiV1MetricsDashboardGetResponseSuccess
  | dashboardMetricsApiV1MetricsDashboardGetResponseError;

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

export const dashboardMetricsApiV1MetricsDashboardGet = async (
  params?: DashboardMetricsApiV1MetricsDashboardGetParams,
  options?: RequestInit,
): Promise<dashboardMetricsApiV1MetricsDashboardGetResponse> => {
  return customFetch<dashboardMetricsApiV1MetricsDashboardGetResponse>(
    getDashboardMetricsApiV1MetricsDashboardGetUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getDashboardMetricsApiV1MetricsDashboardGetQueryKey = (
  params?: DashboardMetricsApiV1MetricsDashboardGetParams,
) => {
  return [`/api/v1/metrics/dashboard`, ...(params ? [params] : [])] as const;
};

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

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

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

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

export type DashboardMetricsApiV1MetricsDashboardGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof dashboardMetricsApiV1MetricsDashboardGet>>
>;
export type DashboardMetricsApiV1MetricsDashboardGetQueryError =
  HTTPValidationError;

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

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

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

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