/**
 * Generated by orval. Do not edit manually.
 * O-replay - OpenAPI 3.0
 * O-replay Rest API
 */
import {
  useMutation,
  useQuery
} from 'react-query';
import type {
  MutationFunction,
  QueryClient,
  QueryFunction,
  QueryKey,
  UseMutationOptions,
  UseMutationResult,
  UseQueryOptions,
  UseQueryResult
} from 'react-query';

import type {
  ArrayStageOrderManagement,
  PatchStageOrdersBody,
  ResStageOrderManagement
} from '../../../domain/types/v1api';

import { orvalAxiosInstance } from '../../orval/orval-axios-instance';


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



/**
 * Get list returns only selected fields
 */
export const getListStageOrders = (
    eventID: string,
    stageID: string,
 options?: SecondParameter<typeof orvalAxiosInstance>,signal?: AbortSignal
) => {
      
      
      return orvalAxiosInstance<ArrayStageOrderManagement>(
      {url: `/api/v1/events/${eventID}/stages/${stageID}/stageOrders/`, method: 'GET', signal
    },
      options);
    }
  



export const getGetListStageOrdersQueryKey = (eventID?: string,
    stageID?: string,) => {
    return [
    `/api/v1/events/${eventID}/stages/${stageID}/stageOrders/`
    ] as const;
    }

    
export const getGetListStageOrdersQueryOptions = <TData = Awaited<ReturnType<typeof getListStageOrders>>, TError = unknown>(eventID: string,
    stageID: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getListStageOrders>>, TError, TData>, request?: SecondParameter<typeof orvalAxiosInstance>}
) => {

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

  const queryKey =  queryOptions?.queryKey ?? getGetListStageOrdersQueryKey(eventID,stageID);

  

    const queryFn: QueryFunction<Awaited<ReturnType<typeof getListStageOrders>>> = ({ signal }) => getListStageOrders(eventID,stageID, requestOptions, signal);

      

      

   return  { queryKey, queryFn, enabled: !!(eventID && stageID), ...queryOptions} as UseQueryOptions<Awaited<ReturnType<typeof getListStageOrders>>, TError, TData> & { queryKey: QueryKey }
}

export type GetListStageOrdersQueryResult = NonNullable<Awaited<ReturnType<typeof getListStageOrders>>>
export type GetListStageOrdersQueryError = unknown



export function useGetListStageOrders<TData = Awaited<ReturnType<typeof getListStageOrders>>, TError = unknown>(
 eventID: string,
    stageID: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getListStageOrders>>, TError, TData>, request?: SecondParameter<typeof orvalAxiosInstance>}
  
 ):  UseQueryResult<TData, TError> & { queryKey: QueryKey } {

  const queryOptions = getGetListStageOrdersQueryOptions(eventID,stageID,options)

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

  query.queryKey = queryOptions.queryKey ;

  return query;
}

export const prefetchGetListStageOrdersQuery = async <TData = Awaited<ReturnType<typeof getListStageOrders>>, TError = unknown>(
 queryClient: QueryClient, eventID: string,
    stageID: string, options?: { query?:UseQueryOptions<Awaited<ReturnType<typeof getListStageOrders>>, TError, TData>, request?: SecondParameter<typeof orvalAxiosInstance>}

  ): Promise<QueryClient> => {

  const queryOptions = getGetListStageOrdersQueryOptions(eventID,stageID,options)

  await queryClient.prefetchQuery(queryOptions);

  return queryClient;
}



/**
 * Edit updates description
 */
export const patchStageOrders = (
    eventID: string,
    stageID: string,
    stageOrderID: string,
    patchStageOrdersBody: PatchStageOrdersBody,
 options?: SecondParameter<typeof orvalAxiosInstance>,) => {
      
      
      return orvalAxiosInstance<ResStageOrderManagement>(
      {url: `/api/v1/events/${eventID}/stages/${stageID}/stageOrders/${stageOrderID}`, method: 'PATCH',
      headers: {'Content-Type': 'application/json', },
      data: patchStageOrdersBody
    },
      options);
    }
  


export const getPatchStageOrdersMutationOptions = <TError = unknown,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchStageOrders>>, TError,{eventID: string;stageID: string;stageOrderID: string;data: PatchStageOrdersBody}, TContext>, request?: SecondParameter<typeof orvalAxiosInstance>}
): UseMutationOptions<Awaited<ReturnType<typeof patchStageOrders>>, TError,{eventID: string;stageID: string;stageOrderID: string;data: PatchStageOrdersBody}, TContext> => {

const mutationKey = ['patchStageOrders'];
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 patchStageOrders>>, {eventID: string;stageID: string;stageOrderID: string;data: PatchStageOrdersBody}> = (props) => {
          const {eventID,stageID,stageOrderID,data} = props ?? {};

          return  patchStageOrders(eventID,stageID,stageOrderID,data,requestOptions)
        }

        


  return  { mutationFn, ...mutationOptions }}

    export type PatchStageOrdersMutationResult = NonNullable<Awaited<ReturnType<typeof patchStageOrders>>>
    export type PatchStageOrdersMutationBody = PatchStageOrdersBody
    export type PatchStageOrdersMutationError = unknown

    export const usePatchStageOrders = <TError = unknown,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof patchStageOrders>>, TError,{eventID: string;stageID: string;stageOrderID: string;data: PatchStageOrdersBody}, TContext>, request?: SecondParameter<typeof orvalAxiosInstance>}
 ): UseMutationResult<
        Awaited<ReturnType<typeof patchStageOrders>>,
        TError,
        {eventID: string;stageID: string;stageOrderID: string;data: PatchStageOrdersBody},
        TContext
      > => {

      const mutationOptions = getPatchStageOrdersMutationOptions(options);

      return useMutation(mutationOptions);
    }
    