/**
 * ! Do not edit manually
 * * The file has been auto-generated using Orval for SigNoz
 * * regenerate with 'yarn generate:api'
 * SigNoz
 */
import { useMutation, useQuery } from 'react-query';
import type {
	InvalidateOptions,
	MutationFunction,
	QueryClient,
	QueryFunction,
	QueryKey,
	UseMutationOptions,
	UseMutationResult,
	UseQueryOptions,
	UseQueryResult,
} from 'react-query';

import type {
	HandleExportRawDataPOSTParams,
	ListPromotedAndIndexedPaths200,
	PromotetypesPromotePathDTO,
	Querybuildertypesv5QueryRangeRequestDTO,
	RenderErrorResponseDTO,
} from '../sigNoz.schemas';

import { GeneratedAPIInstance } from '../../../generatedAPIInstance';
import type { ErrorType, BodyType } from '../../../generatedAPIInstance';

/**
 * This endpoints allows complex query exporting raw data for traces and logs
 * @summary Export raw data
 */
export const handleExportRawDataPOST = (
	querybuildertypesv5QueryRangeRequestDTO: BodyType<Querybuildertypesv5QueryRangeRequestDTO>,
	params?: HandleExportRawDataPOSTParams,
	signal?: AbortSignal,
) => {
	return GeneratedAPIInstance<string>({
		url: `/api/v1/export_raw_data`,
		method: 'POST',
		headers: { 'Content-Type': 'application/json' },
		data: querybuildertypesv5QueryRangeRequestDTO,
		params,
		signal,
	});
};

export const getHandleExportRawDataPOSTMutationOptions = <
	TError = ErrorType<RenderErrorResponseDTO>,
	TContext = unknown,
>(options?: {
	mutation?: UseMutationOptions<
		Awaited<ReturnType<typeof handleExportRawDataPOST>>,
		TError,
		{
			data: BodyType<Querybuildertypesv5QueryRangeRequestDTO>;
			params?: HandleExportRawDataPOSTParams;
		},
		TContext
	>;
}): UseMutationOptions<
	Awaited<ReturnType<typeof handleExportRawDataPOST>>,
	TError,
	{
		data: BodyType<Querybuildertypesv5QueryRangeRequestDTO>;
		params?: HandleExportRawDataPOSTParams;
	},
	TContext
> => {
	const mutationKey = ['handleExportRawDataPOST'];
	const { mutation: mutationOptions } = options
		? options.mutation &&
			'mutationKey' in options.mutation &&
			options.mutation.mutationKey
			? options
			: { ...options, mutation: { ...options.mutation, mutationKey } }
		: { mutation: { mutationKey } };

	const mutationFn: MutationFunction<
		Awaited<ReturnType<typeof handleExportRawDataPOST>>,
		{
			data: BodyType<Querybuildertypesv5QueryRangeRequestDTO>;
			params?: HandleExportRawDataPOSTParams;
		}
	> = (props) => {
		const { data, params } = props ?? {};

		return handleExportRawDataPOST(data, params);
	};

	return { mutationFn, ...mutationOptions };
};

export type HandleExportRawDataPOSTMutationResult = NonNullable<
	Awaited<ReturnType<typeof handleExportRawDataPOST>>
>;
export type HandleExportRawDataPOSTMutationBody =
	BodyType<Querybuildertypesv5QueryRangeRequestDTO>;
export type HandleExportRawDataPOSTMutationError =
	ErrorType<RenderErrorResponseDTO>;

/**
 * @summary Export raw data
 */
export const useHandleExportRawDataPOST = <
	TError = ErrorType<RenderErrorResponseDTO>,
	TContext = unknown,
>(options?: {
	mutation?: UseMutationOptions<
		Awaited<ReturnType<typeof handleExportRawDataPOST>>,
		TError,
		{
			data: BodyType<Querybuildertypesv5QueryRangeRequestDTO>;
			params?: HandleExportRawDataPOSTParams;
		},
		TContext
	>;
}): UseMutationResult<
	Awaited<ReturnType<typeof handleExportRawDataPOST>>,
	TError,
	{
		data: BodyType<Querybuildertypesv5QueryRangeRequestDTO>;
		params?: HandleExportRawDataPOSTParams;
	},
	TContext
> => {
	const mutationOptions = getHandleExportRawDataPOSTMutationOptions(options);

	return useMutation(mutationOptions);
};
/**
 * This endpoints promotes and indexes paths
 * @summary Promote and index paths
 */
export const listPromotedAndIndexedPaths = (signal?: AbortSignal) => {
	return GeneratedAPIInstance<ListPromotedAndIndexedPaths200>({
		url: `/api/v1/logs/promote_paths`,
		method: 'GET',
		signal,
	});
};

export const getListPromotedAndIndexedPathsQueryKey = () => {
	return [`/api/v1/logs/promote_paths`] as const;
};

export const getListPromotedAndIndexedPathsQueryOptions = <
	TData = Awaited<ReturnType<typeof listPromotedAndIndexedPaths>>,
	TError = ErrorType<RenderErrorResponseDTO>,
>(options?: {
	query?: UseQueryOptions<
		Awaited<ReturnType<typeof listPromotedAndIndexedPaths>>,
		TError,
		TData
	>;
}) => {
	const { query: queryOptions } = options ?? {};

	const queryKey =
		queryOptions?.queryKey ?? getListPromotedAndIndexedPathsQueryKey();

	const queryFn: QueryFunction<
		Awaited<ReturnType<typeof listPromotedAndIndexedPaths>>
	> = ({ signal }) => listPromotedAndIndexedPaths(signal);

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

export type ListPromotedAndIndexedPathsQueryResult = NonNullable<
	Awaited<ReturnType<typeof listPromotedAndIndexedPaths>>
>;
export type ListPromotedAndIndexedPathsQueryError =
	ErrorType<RenderErrorResponseDTO>;

/**
 * @summary Promote and index paths
 */

export function useListPromotedAndIndexedPaths<
	TData = Awaited<ReturnType<typeof listPromotedAndIndexedPaths>>,
	TError = ErrorType<RenderErrorResponseDTO>,
>(options?: {
	query?: UseQueryOptions<
		Awaited<ReturnType<typeof listPromotedAndIndexedPaths>>,
		TError,
		TData
	>;
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
	const queryOptions = getListPromotedAndIndexedPathsQueryOptions(options);

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

	query.queryKey = queryOptions.queryKey;

	return query;
}

/**
 * @summary Promote and index paths
 */
export const invalidateListPromotedAndIndexedPaths = async (
	queryClient: QueryClient,
	options?: InvalidateOptions,
): Promise<QueryClient> => {
	await queryClient.invalidateQueries(
		{ queryKey: getListPromotedAndIndexedPathsQueryKey() },
		options,
	);

	return queryClient;
};

/**
 * This endpoints promotes and indexes paths
 * @summary Promote and index paths
 */
export const handlePromoteAndIndexPaths = (
	promotetypesPromotePathDTONull: BodyType<
		PromotetypesPromotePathDTO[] | null
	> | null,
	signal?: AbortSignal,
) => {
	return GeneratedAPIInstance<void>({
		url: `/api/v1/logs/promote_paths`,
		method: 'POST',
		headers: { 'Content-Type': 'application/json' },
		data: promotetypesPromotePathDTONull,
		signal,
	});
};

export const getHandlePromoteAndIndexPathsMutationOptions = <
	TError = ErrorType<RenderErrorResponseDTO>,
	TContext = unknown,
>(options?: {
	mutation?: UseMutationOptions<
		Awaited<ReturnType<typeof handlePromoteAndIndexPaths>>,
		TError,
		{ data: BodyType<PromotetypesPromotePathDTO[] | null> },
		TContext
	>;
}): UseMutationOptions<
	Awaited<ReturnType<typeof handlePromoteAndIndexPaths>>,
	TError,
	{ data: BodyType<PromotetypesPromotePathDTO[] | null> },
	TContext
> => {
	const mutationKey = ['handlePromoteAndIndexPaths'];
	const { mutation: mutationOptions } = options
		? options.mutation &&
			'mutationKey' in options.mutation &&
			options.mutation.mutationKey
			? options
			: { ...options, mutation: { ...options.mutation, mutationKey } }
		: { mutation: { mutationKey } };

	const mutationFn: MutationFunction<
		Awaited<ReturnType<typeof handlePromoteAndIndexPaths>>,
		{ data: BodyType<PromotetypesPromotePathDTO[] | null> }
	> = (props) => {
		const { data } = props ?? {};

		return handlePromoteAndIndexPaths(data);
	};

	return { mutationFn, ...mutationOptions };
};

export type HandlePromoteAndIndexPathsMutationResult = NonNullable<
	Awaited<ReturnType<typeof handlePromoteAndIndexPaths>>
>;
export type HandlePromoteAndIndexPathsMutationBody = BodyType<
	PromotetypesPromotePathDTO[] | null
>;
export type HandlePromoteAndIndexPathsMutationError =
	ErrorType<RenderErrorResponseDTO>;

/**
 * @summary Promote and index paths
 */
export const useHandlePromoteAndIndexPaths = <
	TError = ErrorType<RenderErrorResponseDTO>,
	TContext = unknown,
>(options?: {
	mutation?: UseMutationOptions<
		Awaited<ReturnType<typeof handlePromoteAndIndexPaths>>,
		TError,
		{ data: BodyType<PromotetypesPromotePathDTO[] | null> },
		TContext
	>;
}): UseMutationResult<
	Awaited<ReturnType<typeof handlePromoteAndIndexPaths>>,
	TError,
	{ data: BodyType<PromotetypesPromotePathDTO[] | null> },
	TContext
> => {
	const mutationOptions = getHandlePromoteAndIndexPathsMutationOptions(options);

	return useMutation(mutationOptions);
};
