/**
 * Generated by orval v7.21.0 🍺
 * Do not edit manually.
 * FastAPI
 * 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 {
  AnalysisCreate,
  AnalysisStartResponse,
  AnalysisStatusResponse,
  HTTPValidationError
} from '../../model';

import { customFetcher } from '../../api';


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



/**
 * @summary Start Analysis
 */
export type startAnalysisResponse202 = {
  data: AnalysisStartResponse
  status: 202
}

export type startAnalysisResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type startAnalysisResponseSuccess = (startAnalysisResponse202) & {
  headers: Headers;
};
export type startAnalysisResponseError = (startAnalysisResponse422) & {
  headers: Headers;
};

export type startAnalysisResponse = (startAnalysisResponseSuccess | startAnalysisResponseError)

export const getStartAnalysisUrl = () => {


  

  return `/api/analyses`
}

export const startAnalysis = async (analysisCreate: AnalysisCreate, options?: RequestInit): Promise<startAnalysisResponse> => {
  
  return customFetcher<startAnalysisResponse>(getStartAnalysisUrl(),
  {      
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(
      analysisCreate,)
  }
);}




export const getStartAnalysisMutationOptions = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof startAnalysis>>, TError,{data: AnalysisCreate}, TContext>, request?: SecondParameter<typeof customFetcher>}
): UseMutationOptions<Awaited<ReturnType<typeof startAnalysis>>, TError,{data: AnalysisCreate}, TContext> => {

const mutationKey = ['startAnalysis'];
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 startAnalysis>>, {data: AnalysisCreate}> = (props) => {
          const {data} = props ?? {};

          return  startAnalysis(data,requestOptions)
        }

        


  return  { mutationFn, ...mutationOptions }}

    export type StartAnalysisMutationResult = NonNullable<Awaited<ReturnType<typeof startAnalysis>>>
    export type StartAnalysisMutationBody = AnalysisCreate
    export type StartAnalysisMutationError = HTTPValidationError

    /**
 * @summary Start Analysis
 */
export const useStartAnalysis = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof startAnalysis>>, TError,{data: AnalysisCreate}, TContext>, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient): UseMutationResult<
        Awaited<ReturnType<typeof startAnalysis>>,
        TError,
        {data: AnalysisCreate},
        TContext
      > => {

      const mutationOptions = getStartAnalysisMutationOptions(options);

      return useMutation(mutationOptions, queryClient);
    }
    /**
 * @summary Get Analysis Status
 */
export type getAnalysisStatusResponse200 = {
  data: AnalysisStatusResponse
  status: 200
}

export type getAnalysisStatusResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type getAnalysisStatusResponseSuccess = (getAnalysisStatusResponse200) & {
  headers: Headers;
};
export type getAnalysisStatusResponseError = (getAnalysisStatusResponse422) & {
  headers: Headers;
};

export type getAnalysisStatusResponse = (getAnalysisStatusResponseSuccess | getAnalysisStatusResponseError)

export const getGetAnalysisStatusUrl = (runId: string,) => {


  

  return `/api/analyses/${runId}/status`
}

export const getAnalysisStatus = async (runId: string, options?: RequestInit): Promise<getAnalysisStatusResponse> => {
  
  return customFetcher<getAnalysisStatusResponse>(getGetAnalysisStatusUrl(runId),
  {      
    ...options,
    method: 'GET'
    
    
  }
);}





export const getGetAnalysisStatusQueryKey = (runId?: string,) => {
    return [
    `/api/analyses/${runId}/status`
    ] as const;
    }

    
export const getGetAnalysisStatusQueryOptions = <TData = Awaited<ReturnType<typeof getAnalysisStatus>>, TError = HTTPValidationError>(runId: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnalysisStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetcher>}
) => {

const {query: queryOptions, request: requestOptions} = options ?? {};

  const queryKey =  queryOptions?.queryKey ?? getGetAnalysisStatusQueryKey(runId);

  

    const queryFn: QueryFunction<Awaited<ReturnType<typeof getAnalysisStatus>>> = () => getAnalysisStatus(runId, requestOptions);

      

      

   return  { queryKey, queryFn, enabled: !!(runId),  staleTime: 60000,  ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getAnalysisStatus>>, TError, TData> & { queryKey: DataTag<QueryKey, TData> }
}

export type GetAnalysisStatusQueryResult = NonNullable<Awaited<ReturnType<typeof getAnalysisStatus>>>
export type GetAnalysisStatusQueryError = HTTPValidationError


export function useGetAnalysisStatus<TData = Awaited<ReturnType<typeof getAnalysisStatus>>, TError = HTTPValidationError>(
 runId: string, options: { query:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnalysisStatus>>, TError, TData>> & Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof getAnalysisStatus>>,
          TError,
          Awaited<ReturnType<typeof getAnalysisStatus>>
        > , 'initialData'
      >, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient
  ):  DefinedUseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData> }
export function useGetAnalysisStatus<TData = Awaited<ReturnType<typeof getAnalysisStatus>>, TError = HTTPValidationError>(
 runId: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnalysisStatus>>, TError, TData>> & Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof getAnalysisStatus>>,
          TError,
          Awaited<ReturnType<typeof getAnalysisStatus>>
        > , 'initialData'
      >, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient
  ):  UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData> }
export function useGetAnalysisStatus<TData = Awaited<ReturnType<typeof getAnalysisStatus>>, TError = HTTPValidationError>(
 runId: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnalysisStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient
  ):  UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData> }
/**
 * @summary Get Analysis Status
 */

export function useGetAnalysisStatus<TData = Awaited<ReturnType<typeof getAnalysisStatus>>, TError = HTTPValidationError>(
 runId: string, options?: { query?:Partial<UseQueryOptions<Awaited<ReturnType<typeof getAnalysisStatus>>, TError, TData>>, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient 
 ):  UseQueryResult<TData, TError> & { queryKey: DataTag<QueryKey, TData> } {

  const queryOptions = getGetAnalysisStatusQueryOptions(runId,options)

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

  query.queryKey = queryOptions.queryKey ;

  return query;
}




