/**
 * 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 {
  GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  HTTPValidationError,
  ProviderCredentialCreate,
  ProviderCredentialRead,
  ProviderCredentialUpdate,
  ProviderUsageLiveRead,
} from ".././model";

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

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

/**
 * List all provider credentials for the caller's organisation.
 * @summary List Provider Credentials
 */
export type listProviderCredentialsApiV1ProviderCredentialsGetResponse200 = {
  data: ProviderCredentialRead[];
  status: 200;
};

export type listProviderCredentialsApiV1ProviderCredentialsGetResponseSuccess =
  listProviderCredentialsApiV1ProviderCredentialsGetResponse200 & {
    headers: Headers;
  };
export type listProviderCredentialsApiV1ProviderCredentialsGetResponse =
  listProviderCredentialsApiV1ProviderCredentialsGetResponseSuccess;

export const getListProviderCredentialsApiV1ProviderCredentialsGetUrl = () => {
  return `/api/v1/provider-credentials`;
};

export const listProviderCredentialsApiV1ProviderCredentialsGet = async (
  options?: RequestInit,
): Promise<listProviderCredentialsApiV1ProviderCredentialsGetResponse> => {
  return customFetch<listProviderCredentialsApiV1ProviderCredentialsGetResponse>(
    getListProviderCredentialsApiV1ProviderCredentialsGetUrl(),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getListProviderCredentialsApiV1ProviderCredentialsGetQueryKey =
  () => {
    return [`/api/v1/provider-credentials`] as const;
  };

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

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

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

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

export type ListProviderCredentialsApiV1ProviderCredentialsGetQueryResult =
  NonNullable<
    Awaited<
      ReturnType<typeof listProviderCredentialsApiV1ProviderCredentialsGet>
    >
  >;
export type ListProviderCredentialsApiV1ProviderCredentialsGetQueryError =
  unknown;

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

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

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

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

/**
 * Create a new provider credential. Admin-only.
 * @summary Create Provider Credential
 */
export type createProviderCredentialApiV1ProviderCredentialsPostResponse201 = {
  data: ProviderCredentialRead;
  status: 201;
};

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

export type createProviderCredentialApiV1ProviderCredentialsPostResponseSuccess =
  createProviderCredentialApiV1ProviderCredentialsPostResponse201 & {
    headers: Headers;
  };
export type createProviderCredentialApiV1ProviderCredentialsPostResponseError =
  createProviderCredentialApiV1ProviderCredentialsPostResponse422 & {
    headers: Headers;
  };

export type createProviderCredentialApiV1ProviderCredentialsPostResponse =
  | createProviderCredentialApiV1ProviderCredentialsPostResponseSuccess
  | createProviderCredentialApiV1ProviderCredentialsPostResponseError;

export const getCreateProviderCredentialApiV1ProviderCredentialsPostUrl =
  () => {
    return `/api/v1/provider-credentials`;
  };

export const createProviderCredentialApiV1ProviderCredentialsPost = async (
  providerCredentialCreate: ProviderCredentialCreate,
  options?: RequestInit,
): Promise<createProviderCredentialApiV1ProviderCredentialsPostResponse> => {
  return customFetch<createProviderCredentialApiV1ProviderCredentialsPostResponse>(
    getCreateProviderCredentialApiV1ProviderCredentialsPostUrl(),
    {
      ...options,
      method: "POST",
      headers: { "Content-Type": "application/json", ...options?.headers },
      body: JSON.stringify(providerCredentialCreate),
    },
  );
};

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

      return createProviderCredentialApiV1ProviderCredentialsPost(
        data,
        requestOptions,
      );
    };

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

export type CreateProviderCredentialApiV1ProviderCredentialsPostMutationResult =
  NonNullable<
    Awaited<
      ReturnType<typeof createProviderCredentialApiV1ProviderCredentialsPost>
    >
  >;
export type CreateProviderCredentialApiV1ProviderCredentialsPostMutationBody =
  ProviderCredentialCreate;
export type CreateProviderCredentialApiV1ProviderCredentialsPostMutationError =
  HTTPValidationError;

/**
 * @summary Create Provider Credential
 */
export const useCreateProviderCredentialApiV1ProviderCredentialsPost = <
  TError = HTTPValidationError,
  TContext = unknown,
>(
  options?: {
    mutation?: UseMutationOptions<
      Awaited<
        ReturnType<typeof createProviderCredentialApiV1ProviderCredentialsPost>
      >,
      TError,
      { data: ProviderCredentialCreate },
      TContext
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseMutationResult<
  Awaited<
    ReturnType<typeof createProviderCredentialApiV1ProviderCredentialsPost>
  >,
  TError,
  { data: ProviderCredentialCreate },
  TContext
> => {
  return useMutation(
    getCreateProviderCredentialApiV1ProviderCredentialsPostMutationOptions(
      options,
    ),
    queryClient,
  );
};
/**
 * @summary Get Provider Credential
 */
export type getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponse200 =
  {
    data: ProviderCredentialRead;
    status: 200;
  };

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

export type getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponseSuccess =
  getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponse200 & {
    headers: Headers;
  };
export type getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponseError =
  getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponse422 & {
    headers: Headers;
  };

export type getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponse =

    | getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponseSuccess
    | getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponseError;

export const getGetProviderCredentialApiV1ProviderCredentialsCredentialIdGetUrl =
  (credentialId: string) => {
    return `/api/v1/provider-credentials/${credentialId}`;
  };

export const getProviderCredentialApiV1ProviderCredentialsCredentialIdGet =
  async (
    credentialId: string,
    options?: RequestInit,
  ): Promise<getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponse> => {
    return customFetch<getProviderCredentialApiV1ProviderCredentialsCredentialIdGetResponse>(
      getGetProviderCredentialApiV1ProviderCredentialsCredentialIdGetUrl(
        credentialId,
      ),
      {
        ...options,
        method: "GET",
      },
    );
  };

export const getGetProviderCredentialApiV1ProviderCredentialsCredentialIdGetQueryKey =
  (credentialId: string) => {
    return [`/api/v1/provider-credentials/${credentialId}`] as const;
  };

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

    const queryKey =
      queryOptions?.queryKey ??
      getGetProviderCredentialApiV1ProviderCredentialsCredentialIdGetQueryKey(
        credentialId,
      );

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

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

export type GetProviderCredentialApiV1ProviderCredentialsCredentialIdGetQueryResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof getProviderCredentialApiV1ProviderCredentialsCredentialIdGet
      >
    >
  >;
export type GetProviderCredentialApiV1ProviderCredentialsCredentialIdGetQueryError =
  HTTPValidationError;

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

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

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

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

/**
 * Update a credential. Pass api_key="" to clear it. Admin-only.
 * @summary Update Provider Credential
 */
export type updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponse200 =
  {
    data: ProviderCredentialRead;
    status: 200;
  };

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

export type updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponseSuccess =
  updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponse200 & {
    headers: Headers;
  };
export type updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponseError =
  updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponse422 & {
    headers: Headers;
  };

export type updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponse =

    | updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponseSuccess
    | updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponseError;

export const getUpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchUrl =
  (credentialId: string) => {
    return `/api/v1/provider-credentials/${credentialId}`;
  };

export const updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatch =
  async (
    credentialId: string,
    providerCredentialUpdate: ProviderCredentialUpdate,
    options?: RequestInit,
  ): Promise<updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponse> => {
    return customFetch<updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchResponse>(
      getUpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchUrl(
        credentialId,
      ),
      {
        ...options,
        method: "PATCH",
        headers: { "Content-Type": "application/json", ...options?.headers },
        body: JSON.stringify(providerCredentialUpdate),
      },
    );
  };

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

      return updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatch(
        credentialId,
        data,
        requestOptions,
      );
    };

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

export type UpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatch
      >
    >
  >;
export type UpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchMutationBody =
  ProviderCredentialUpdate;
export type UpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchMutationError =
  HTTPValidationError;

/**
 * @summary Update Provider Credential
 */
export const useUpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatch =
  <TError = HTTPValidationError, TContext = unknown>(
    options?: {
      mutation?: UseMutationOptions<
        Awaited<
          ReturnType<
            typeof updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatch
          >
        >,
        TError,
        { credentialId: string; data: ProviderCredentialUpdate },
        TContext
      >;
      request?: SecondParameter<typeof customFetch>;
    },
    queryClient?: QueryClient,
  ): UseMutationResult<
    Awaited<
      ReturnType<
        typeof updateProviderCredentialApiV1ProviderCredentialsCredentialIdPatch
      >
    >,
    TError,
    { credentialId: string; data: ProviderCredentialUpdate },
    TContext
  > => {
    return useMutation(
      getUpdateProviderCredentialApiV1ProviderCredentialsCredentialIdPatchMutationOptions(
        options,
      ),
      queryClient,
    );
  };
/**
 * Delete a credential. Admin-only.
 * @summary Delete Provider Credential
 */
export type deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponse204 =
  {
    data: void;
    status: 204;
  };

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

export type deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponseSuccess =
  deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponse204 & {
    headers: Headers;
  };
export type deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponseError =
  deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponse422 & {
    headers: Headers;
  };

export type deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponse =

    | deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponseSuccess
    | deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponseError;

export const getDeleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteUrl =
  (credentialId: string) => {
    return `/api/v1/provider-credentials/${credentialId}`;
  };

export const deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDelete =
  async (
    credentialId: string,
    options?: RequestInit,
  ): Promise<deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponse> => {
    return customFetch<deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteResponse>(
      getDeleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteUrl(
        credentialId,
      ),
      {
        ...options,
        method: "DELETE",
      },
    );
  };

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

      return deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDelete(
        credentialId,
        requestOptions,
      );
    };

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

export type DeleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteMutationResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDelete
      >
    >
  >;

export type DeleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteMutationError =
  HTTPValidationError;

/**
 * @summary Delete Provider Credential
 */
export const useDeleteProviderCredentialApiV1ProviderCredentialsCredentialIdDelete =
  <TError = HTTPValidationError, TContext = unknown>(
    options?: {
      mutation?: UseMutationOptions<
        Awaited<
          ReturnType<
            typeof deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDelete
          >
        >,
        TError,
        { credentialId: string },
        TContext
      >;
      request?: SecondParameter<typeof customFetch>;
    },
    queryClient?: QueryClient,
  ): UseMutationResult<
    Awaited<
      ReturnType<
        typeof deleteProviderCredentialApiV1ProviderCredentialsCredentialIdDelete
      >
    >,
    TError,
    { credentialId: string },
    TContext
  > => {
    return useMutation(
      getDeleteProviderCredentialApiV1ProviderCredentialsCredentialIdDeleteMutationOptions(
        options,
      ),
      queryClient,
    );
  };
/**
 * Fetch live token usage and rate limits directly from the provider API.

Calls the provider's model-list endpoint (zero token cost) and reads the
rate-limit response headers.  Results are cached for 60 seconds.
Pass ?refresh=true to force a fresh fetch.
 * @summary Get Provider Usage Live
 */
export type getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponse200 =
  {
    data: ProviderUsageLiveRead;
    status: 200;
  };

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

export type getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponseSuccess =
  getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponse200 & {
    headers: Headers;
  };
export type getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponseError =
  getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponse422 & {
    headers: Headers;
  };

export type getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponse =

    | getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponseSuccess
    | getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponseError;

export const getGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetUrl =
  (
    credentialId: string,
    params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  ) => {
    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/provider-credentials/${credentialId}/usage?${stringifiedParams}`
      : `/api/v1/provider-credentials/${credentialId}/usage`;
  };

export const getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet =
  async (
    credentialId: string,
    params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
    options?: RequestInit,
  ): Promise<getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponse> => {
    return customFetch<getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetResponse>(
      getGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetUrl(
        credentialId,
        params,
      ),
      {
        ...options,
        method: "GET",
      },
    );
  };

export const getGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetQueryKey =
  (
    credentialId: string,
    params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  ) => {
    return [
      `/api/v1/provider-credentials/${credentialId}/usage`,
      ...(params ? [params] : []),
    ] as const;
  };

export const getGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetQueryOptions =
  <
    TData = Awaited<
      ReturnType<
        typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
      >
    >,
    TError = HTTPValidationError,
  >(
    credentialId: string,
    params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
    options?: {
      query?: Partial<
        UseQueryOptions<
          Awaited<
            ReturnType<
              typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
            >
          >,
          TError,
          TData
        >
      >;
      request?: SecondParameter<typeof customFetch>;
    },
  ) => {
    const { query: queryOptions, request: requestOptions } = options ?? {};

    const queryKey =
      queryOptions?.queryKey ??
      getGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetQueryKey(
        credentialId,
        params,
      );

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

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

export type GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetQueryResult =
  NonNullable<
    Awaited<
      ReturnType<
        typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
      >
    >
  >;
export type GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetQueryError =
  HTTPValidationError;

export function useGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet<
  TData = Awaited<
    ReturnType<
      typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
    >
  >,
  TError = HTTPValidationError,
>(
  credentialId: string,
  params:
    | undefined
    | GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<
          ReturnType<
            typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
          >
        >,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<
            ReturnType<
              typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
            >
          >,
          TError,
          Awaited<
            ReturnType<
              typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
            >
          >
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet<
  TData = Awaited<
    ReturnType<
      typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
    >
  >,
  TError = HTTPValidationError,
>(
  credentialId: string,
  params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<
          ReturnType<
            typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
          >
        >,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<
            ReturnType<
              typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
            >
          >,
          TError,
          Awaited<
            ReturnType<
              typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
            >
          >
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet<
  TData = Awaited<
    ReturnType<
      typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
    >
  >,
  TError = HTTPValidationError,
>(
  credentialId: string,
  params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<
          ReturnType<
            typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
          >
        >,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Get Provider Usage Live
 */

export function useGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet<
  TData = Awaited<
    ReturnType<
      typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
    >
  >,
  TError = HTTPValidationError,
>(
  credentialId: string,
  params?: GetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<
          ReturnType<
            typeof getProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGet
          >
        >,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions =
    getGetProviderUsageLiveApiV1ProviderCredentialsCredentialIdUsageGetQueryOptions(
      credentialId,
      params,
      options,
    );

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

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