/**
 * 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,
  BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost,
  FileListItem,
  FileUploadResponse,
  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/analysis`
}

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 Upload Analysis Run File
 */
export type uploadAnalysisRunFileResponse201 = {
  data: FileUploadResponse
  status: 201
}

export type uploadAnalysisRunFileResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type uploadAnalysisRunFileResponseSuccess = (uploadAnalysisRunFileResponse201) & {
  headers: Headers;
};
export type uploadAnalysisRunFileResponseError = (uploadAnalysisRunFileResponse422) & {
  headers: Headers;
};

export type uploadAnalysisRunFileResponse = (uploadAnalysisRunFileResponseSuccess | uploadAnalysisRunFileResponseError)

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


  

  return `/api/analysis/${runId}/files`
}

export const uploadAnalysisRunFile = async (runId: string,
    bodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost: BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost, options?: RequestInit): Promise<uploadAnalysisRunFileResponse> => {
    const formData = new FormData();
formData.append(`file`, bodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost.file)
if(bodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost.file_type !== undefined) {
 formData.append(`file_type`, bodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost.file_type)
 }

  return customFetcher<uploadAnalysisRunFileResponse>(getUploadAnalysisRunFileUrl(runId),
  {      
    ...options,
    method: 'POST'
    ,
    body: 
      formData,
  }
);}




export const getUploadAnalysisRunFileMutationOptions = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadAnalysisRunFile>>, TError,{runId: string;data: BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost}, TContext>, request?: SecondParameter<typeof customFetcher>}
): UseMutationOptions<Awaited<ReturnType<typeof uploadAnalysisRunFile>>, TError,{runId: string;data: BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost}, TContext> => {

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

          return  uploadAnalysisRunFile(runId,data,requestOptions)
        }

        


  return  { mutationFn, ...mutationOptions }}

    export type UploadAnalysisRunFileMutationResult = NonNullable<Awaited<ReturnType<typeof uploadAnalysisRunFile>>>
    export type UploadAnalysisRunFileMutationBody = BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost
    export type UploadAnalysisRunFileMutationError = HTTPValidationError

    /**
 * @summary Upload Analysis Run File
 */
export const useUploadAnalysisRunFile = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof uploadAnalysisRunFile>>, TError,{runId: string;data: BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost}, TContext>, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient): UseMutationResult<
        Awaited<ReturnType<typeof uploadAnalysisRunFile>>,
        TError,
        {runId: string;data: BodyUploadAnalysisRunFileApiAnalysisRunIdFilesPost},
        TContext
      > => {

      const mutationOptions = getUploadAnalysisRunFileMutationOptions(options);

      return useMutation(mutationOptions, queryClient);
    }
    /**
 * @summary Get Analysis Run Files
 */
export type getAnalysisRunFilesResponse200 = {
  data: FileListItem[]
  status: 200
}

export type getAnalysisRunFilesResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type getAnalysisRunFilesResponseSuccess = (getAnalysisRunFilesResponse200) & {
  headers: Headers;
};
export type getAnalysisRunFilesResponseError = (getAnalysisRunFilesResponse422) & {
  headers: Headers;
};

export type getAnalysisRunFilesResponse = (getAnalysisRunFilesResponseSuccess | getAnalysisRunFilesResponseError)

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


  

  return `/api/analysis/${runId}/files`
}

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





export const getGetAnalysisRunFilesQueryKey = (runId?: string,) => {
    return [
    `/api/analysis/${runId}/files`
    ] as const;
    }

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

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

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

  

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

      

      

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

export type GetAnalysisRunFilesQueryResult = NonNullable<Awaited<ReturnType<typeof getAnalysisRunFiles>>>
export type GetAnalysisRunFilesQueryError = HTTPValidationError


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

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

  const queryOptions = getGetAnalysisRunFilesQueryOptions(runId,options)

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

  query.queryKey = queryOptions.queryKey ;

  return query;
}




/**
 * @summary Delete Analysis Run File
 */
export type deleteAnalysisRunFileResponse204 = {
  data: void
  status: 204
}

export type deleteAnalysisRunFileResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type deleteAnalysisRunFileResponseSuccess = (deleteAnalysisRunFileResponse204) & {
  headers: Headers;
};
export type deleteAnalysisRunFileResponseError = (deleteAnalysisRunFileResponse422) & {
  headers: Headers;
};

export type deleteAnalysisRunFileResponse = (deleteAnalysisRunFileResponseSuccess | deleteAnalysisRunFileResponseError)

export const getDeleteAnalysisRunFileUrl = (runId: string,
    fileId: number,) => {


  

  return `/api/analysis/${runId}/files/${fileId}`
}

export const deleteAnalysisRunFile = async (runId: string,
    fileId: number, options?: RequestInit): Promise<deleteAnalysisRunFileResponse> => {
  
  return customFetcher<deleteAnalysisRunFileResponse>(getDeleteAnalysisRunFileUrl(runId,fileId),
  {      
    ...options,
    method: 'DELETE'
    
    
  }
);}




export const getDeleteAnalysisRunFileMutationOptions = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteAnalysisRunFile>>, TError,{runId: string;fileId: number}, TContext>, request?: SecondParameter<typeof customFetcher>}
): UseMutationOptions<Awaited<ReturnType<typeof deleteAnalysisRunFile>>, TError,{runId: string;fileId: number}, TContext> => {

const mutationKey = ['deleteAnalysisRunFile'];
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 deleteAnalysisRunFile>>, {runId: string;fileId: number}> = (props) => {
          const {runId,fileId} = props ?? {};

          return  deleteAnalysisRunFile(runId,fileId,requestOptions)
        }

        


  return  { mutationFn, ...mutationOptions }}

    export type DeleteAnalysisRunFileMutationResult = NonNullable<Awaited<ReturnType<typeof deleteAnalysisRunFile>>>
    
    export type DeleteAnalysisRunFileMutationError = HTTPValidationError

    /**
 * @summary Delete Analysis Run File
 */
export const useDeleteAnalysisRunFile = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof deleteAnalysisRunFile>>, TError,{runId: string;fileId: number}, TContext>, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient): UseMutationResult<
        Awaited<ReturnType<typeof deleteAnalysisRunFile>>,
        TError,
        {runId: string;fileId: number},
        TContext
      > => {

      const mutationOptions = getDeleteAnalysisRunFileMutationOptions(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/analysis/${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/analysis/${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;
}




