/**
 * Generated by orval v8.3.0 🍺
 * Do not edit manually.
 * Mission Control API
 * OpenAPI spec version: 0.1.0
 */
import { useQuery } from "@tanstack/react-query";
import type {
  DataTag,
  DefinedInitialDataOptions,
  DefinedUseQueryResult,
  QueryClient,
  QueryFunction,
  QueryKey,
  UndefinedInitialDataOptions,
  UseQueryOptions,
  UseQueryResult,
} from "@tanstack/react-query";

import type {
  HTTPValidationError,
  SearchApiV1SoulsDirectorySearchGetParams,
  SoulsDirectoryMarkdownResponse,
  SoulsDirectorySearchResponse,
} from ".././model";

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

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

/**
 * Search souls-directory entries by handle/slug query text.
 * @summary Search
 */
export type searchApiV1SoulsDirectorySearchGetResponse200 = {
  data: SoulsDirectorySearchResponse;
  status: 200;
};

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

export type searchApiV1SoulsDirectorySearchGetResponseSuccess =
  searchApiV1SoulsDirectorySearchGetResponse200 & {
    headers: Headers;
  };
export type searchApiV1SoulsDirectorySearchGetResponseError =
  searchApiV1SoulsDirectorySearchGetResponse422 & {
    headers: Headers;
  };

export type searchApiV1SoulsDirectorySearchGetResponse =
  | searchApiV1SoulsDirectorySearchGetResponseSuccess
  | searchApiV1SoulsDirectorySearchGetResponseError;

export const getSearchApiV1SoulsDirectorySearchGetUrl = (
  params?: SearchApiV1SoulsDirectorySearchGetParams,
) => {
  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/souls-directory/search?${stringifiedParams}`
    : `/api/v1/souls-directory/search`;
};

export const searchApiV1SoulsDirectorySearchGet = async (
  params?: SearchApiV1SoulsDirectorySearchGetParams,
  options?: RequestInit,
): Promise<searchApiV1SoulsDirectorySearchGetResponse> => {
  return customFetch<searchApiV1SoulsDirectorySearchGetResponse>(
    getSearchApiV1SoulsDirectorySearchGetUrl(params),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getSearchApiV1SoulsDirectorySearchGetQueryKey = (
  params?: SearchApiV1SoulsDirectorySearchGetParams,
) => {
  return [
    `/api/v1/souls-directory/search`,
    ...(params ? [params] : []),
  ] as const;
};

export const getSearchApiV1SoulsDirectorySearchGetQueryOptions = <
  TData = Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
  TError = HTTPValidationError,
>(
  params?: SearchApiV1SoulsDirectorySearchGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
) => {
  const { query: queryOptions, request: requestOptions } = options ?? {};

  const queryKey =
    queryOptions?.queryKey ??
    getSearchApiV1SoulsDirectorySearchGetQueryKey(params);

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

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

export type SearchApiV1SoulsDirectorySearchGetQueryResult = NonNullable<
  Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>
>;
export type SearchApiV1SoulsDirectorySearchGetQueryError = HTTPValidationError;

export function useSearchApiV1SoulsDirectorySearchGet<
  TData = Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
  TError = HTTPValidationError,
>(
  params: undefined | SearchApiV1SoulsDirectorySearchGetParams,
  options: {
    query: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
        TError,
        TData
      >
    > &
      Pick<
        DefinedInitialDataOptions<
          Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
          TError,
          Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): DefinedUseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useSearchApiV1SoulsDirectorySearchGet<
  TData = Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
  TError = HTTPValidationError,
>(
  params?: SearchApiV1SoulsDirectorySearchGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
        TError,
        TData
      >
    > &
      Pick<
        UndefinedInitialDataOptions<
          Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
          TError,
          Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>
        >,
        "initialData"
      >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
export function useSearchApiV1SoulsDirectorySearchGet<
  TData = Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
  TError = HTTPValidationError,
>(
  params?: SearchApiV1SoulsDirectorySearchGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
};
/**
 * @summary Search
 */

export function useSearchApiV1SoulsDirectorySearchGet<
  TData = Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
  TError = HTTPValidationError,
>(
  params?: SearchApiV1SoulsDirectorySearchGetParams,
  options?: {
    query?: Partial<
      UseQueryOptions<
        Awaited<ReturnType<typeof searchApiV1SoulsDirectorySearchGet>>,
        TError,
        TData
      >
    >;
    request?: SecondParameter<typeof customFetch>;
  },
  queryClient?: QueryClient,
): UseQueryResult<TData, TError> & {
  queryKey: DataTag<QueryKey, TData, TError>;
} {
  const queryOptions = getSearchApiV1SoulsDirectorySearchGetQueryOptions(
    params,
    options,
  );

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

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

/**
 * Fetch markdown content for a validated souls-directory handle and slug.
 * @summary Get Markdown
 */
export type getMarkdownApiV1SoulsDirectoryHandleSlugGetResponse200 = {
  data: SoulsDirectoryMarkdownResponse;
  status: 200;
};

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

export type getMarkdownApiV1SoulsDirectoryHandleSlugGetResponseSuccess =
  getMarkdownApiV1SoulsDirectoryHandleSlugGetResponse200 & {
    headers: Headers;
  };
export type getMarkdownApiV1SoulsDirectoryHandleSlugGetResponseError =
  getMarkdownApiV1SoulsDirectoryHandleSlugGetResponse422 & {
    headers: Headers;
  };

export type getMarkdownApiV1SoulsDirectoryHandleSlugGetResponse =
  | getMarkdownApiV1SoulsDirectoryHandleSlugGetResponseSuccess
  | getMarkdownApiV1SoulsDirectoryHandleSlugGetResponseError;

export const getGetMarkdownApiV1SoulsDirectoryHandleSlugGetUrl = (
  handle: string,
  slug: string,
) => {
  return `/api/v1/souls-directory/${handle}/${slug}`;
};

export const getMarkdownApiV1SoulsDirectoryHandleSlugGet = async (
  handle: string,
  slug: string,
  options?: RequestInit,
): Promise<getMarkdownApiV1SoulsDirectoryHandleSlugGetResponse> => {
  return customFetch<getMarkdownApiV1SoulsDirectoryHandleSlugGetResponse>(
    getGetMarkdownApiV1SoulsDirectoryHandleSlugGetUrl(handle, slug),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetMarkdownApiV1SoulsDirectoryHandleSlugGetQueryKey = (
  handle: string,
  slug: string,
) => {
  return [`/api/v1/souls-directory/${handle}/${slug}`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ??
    getGetMarkdownApiV1SoulsDirectoryHandleSlugGetQueryKey(handle, slug);

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

  return {
    queryKey,
    queryFn,
    enabled: !!(handle && slug),
    ...queryOptions,
  } as UseQueryOptions<
    Awaited<ReturnType<typeof getMarkdownApiV1SoulsDirectoryHandleSlugGet>>,
    TError,
    TData
  > & { queryKey: DataTag<QueryKey, TData, TError> };
};

export type GetMarkdownApiV1SoulsDirectoryHandleSlugGetQueryResult =
  NonNullable<
    Awaited<ReturnType<typeof getMarkdownApiV1SoulsDirectoryHandleSlugGet>>
  >;
export type GetMarkdownApiV1SoulsDirectoryHandleSlugGetQueryError =
  HTTPValidationError;

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

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

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

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

/**
 * Fetch markdown content for a validated souls-directory handle and slug.
 * @summary Get Markdown
 */
export type getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponse200 = {
  data: SoulsDirectoryMarkdownResponse;
  status: 200;
};

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

export type getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponseSuccess =
  getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponse200 & {
    headers: Headers;
  };
export type getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponseError =
  getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponse422 & {
    headers: Headers;
  };

export type getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponse =
  | getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponseSuccess
  | getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponseError;

export const getGetMarkdownApiV1SoulsDirectoryHandleSlugMdGetUrl = (
  handle: string,
  slug: string,
) => {
  return `/api/v1/souls-directory/${handle}/${slug}.md`;
};

export const getMarkdownApiV1SoulsDirectoryHandleSlugMdGet = async (
  handle: string,
  slug: string,
  options?: RequestInit,
): Promise<getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponse> => {
  return customFetch<getMarkdownApiV1SoulsDirectoryHandleSlugMdGetResponse>(
    getGetMarkdownApiV1SoulsDirectoryHandleSlugMdGetUrl(handle, slug),
    {
      ...options,
      method: "GET",
    },
  );
};

export const getGetMarkdownApiV1SoulsDirectoryHandleSlugMdGetQueryKey = (
  handle: string,
  slug: string,
) => {
  return [`/api/v1/souls-directory/${handle}/${slug}.md`] as const;
};

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

  const queryKey =
    queryOptions?.queryKey ??
    getGetMarkdownApiV1SoulsDirectoryHandleSlugMdGetQueryKey(handle, slug);

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

  return {
    queryKey,
    queryFn,
    enabled: !!(handle && slug),
    ...queryOptions,
  } as UseQueryOptions<
    Awaited<ReturnType<typeof getMarkdownApiV1SoulsDirectoryHandleSlugMdGet>>,
    TError,
    TData
  > & { queryKey: DataTag<QueryKey, TData, TError> };
};

export type GetMarkdownApiV1SoulsDirectoryHandleSlugMdGetQueryResult =
  NonNullable<
    Awaited<ReturnType<typeof getMarkdownApiV1SoulsDirectoryHandleSlugMdGet>>
  >;
export type GetMarkdownApiV1SoulsDirectoryHandleSlugMdGetQueryError =
  HTTPValidationError;

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

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

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

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