/**
 * 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 {
  HTTPValidationError,
  PlanCreate,
  PlanResponse
} from '../../model';

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


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



/**
 * @summary Create Plan
 */
export type createPlanResponse201 = {
  data: PlanResponse
  status: 201
}

export type createPlanResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type createPlanResponseSuccess = (createPlanResponse201) & {
  headers: Headers;
};
export type createPlanResponseError = (createPlanResponse422) & {
  headers: Headers;
};

export type createPlanResponse = (createPlanResponseSuccess | createPlanResponseError)

export const getCreatePlanUrl = () => {


  

  return `/api/plans`
}

export const createPlan = async (planCreate: PlanCreate, options?: RequestInit): Promise<createPlanResponse> => {
  
  return customFetcher<createPlanResponse>(getCreatePlanUrl(),
  {      
    ...options,
    method: 'POST',
    headers: { 'Content-Type': 'application/json', ...options?.headers },
    body: JSON.stringify(
      planCreate,)
  }
);}




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

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

          return  createPlan(data,requestOptions)
        }

        


  return  { mutationFn, ...mutationOptions }}

    export type CreatePlanMutationResult = NonNullable<Awaited<ReturnType<typeof createPlan>>>
    export type CreatePlanMutationBody = PlanCreate
    export type CreatePlanMutationError = HTTPValidationError

    /**
 * @summary Create Plan
 */
export const useCreatePlan = <TError = HTTPValidationError,
    TContext = unknown>(options?: { mutation?:UseMutationOptions<Awaited<ReturnType<typeof createPlan>>, TError,{data: PlanCreate}, TContext>, request?: SecondParameter<typeof customFetcher>}
 , queryClient?: QueryClient): UseMutationResult<
        Awaited<ReturnType<typeof createPlan>>,
        TError,
        {data: PlanCreate},
        TContext
      > => {

      const mutationOptions = getCreatePlanMutationOptions(options);

      return useMutation(mutationOptions, queryClient);
    }
    /**
 * @summary Get Plan
 */
export type getPlanResponse200 = {
  data: PlanResponse
  status: 200
}

export type getPlanResponse422 = {
  data: HTTPValidationError
  status: 422
}
    
export type getPlanResponseSuccess = (getPlanResponse200) & {
  headers: Headers;
};
export type getPlanResponseError = (getPlanResponse422) & {
  headers: Headers;
};

export type getPlanResponse = (getPlanResponseSuccess | getPlanResponseError)

export const getGetPlanUrl = (id: string,) => {


  

  return `/api/plans/${id}`
}

export const getPlan = async (id: string, options?: RequestInit): Promise<getPlanResponse> => {
  
  return customFetcher<getPlanResponse>(getGetPlanUrl(id),
  {      
    ...options,
    method: 'GET'
    
    
  }
);}





export const getGetPlanQueryKey = (id?: string,) => {
    return [
    `/api/plans/${id}`
    ] as const;
    }

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

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

  const queryKey =  queryOptions?.queryKey ?? getGetPlanQueryKey(id);

  

    const queryFn: QueryFunction<Awaited<ReturnType<typeof getPlan>>> = () => getPlan(id, requestOptions);

      

      

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

export type GetPlanQueryResult = NonNullable<Awaited<ReturnType<typeof getPlan>>>
export type GetPlanQueryError = HTTPValidationError


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

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

  const queryOptions = getGetPlanQueryOptions(id,options)

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

  query.queryKey = queryOptions.queryKey ;

  return query;
}




