import { Result } from "neverthrow";
import { QueryClient as QueryClient$1, QueryClient as TanstackQueryClient, QueryClientConfig } from "@tanstack/vue-query";
import { App, ComputedRef, MaybeRef, Ref } from "vue";

//#region src/async-result/asyncResult.d.ts
/**
 * Base class for AsyncResult - internal use only.
 * Use AsyncResult<T, E> as the public type.
 */
declare abstract class AsyncResultBase<T, E> {
  protected readonly _error: E | undefined;
  protected readonly _status: 'err' | 'loading' | 'ok';
  protected readonly _value: T | undefined;
  protected constructor(status: 'err' | 'loading' | 'ok', value?: T, error?: E);
  /**
   * Check if the result is an error (type predicate for narrowing)
   */
  isErr(): this is AsyncResultErr<T, E>;
  /**
   * Check if the result is in loading state (type predicate for narrowing)
   */
  isLoading(): this is AsyncResultLoading<T, E>;
  /**
   * Check if the result is a success (type predicate for narrowing)
   */
  isOk(): this is AsyncResultOk<T, E>;
  /**
   * Map the success value to a new value
   */
  map<U>(fn: (value: T) => U): AsyncResult<U, E>;
  /**
   * Map the error to a new error
   */
  mapErr<F>(fn: (error: E) => F): AsyncResult<T, F>;
  /**
   * Pattern match on all three states
   */
  match<U>(handlers: {
    err: (error: E) => U;
    loading: () => U;
    ok: (value: T) => U;
  }): U;
  /**
   * Get the success value, or return null if loading or error.
   * Returns T | null when null is passed as the default value.
   */
  unwrapOr(defaultValue: null): T | null;
  /**
   * Get the success value, or return the default value of type T if loading or error.
   * Returns T when a value of type T is passed as the default value.
   */
  unwrapOr(defaultValue: T): T;
}
/**
 * AsyncResult representing an error state
 */
declare class AsyncResultErr<T, E> extends AsyncResultBase<T, E> {
  private constructor();
  /** @internal */
  static _create<T, E>(error: E): AsyncResultErr<T, E>;
  /** Get the error value - only available after isErr() check */
  getError(): E;
  getResult(): Result<T, E>;
}
/**
 * AsyncResult representing a loading state
 */
declare class AsyncResultLoading<T, E> extends AsyncResultBase<T, E> {
  private constructor();
  /** @internal */
  static _create<T, E>(): AsyncResultLoading<T, E>;
  getResult(): null;
}
/**
 * AsyncResult representing a success state
 */
declare class AsyncResultOk<T, E> extends AsyncResultBase<T, E> {
  private constructor();
  /** @internal */
  static _create<T, E>(value: T): AsyncResultOk<T, E>;
  getResult(): Result<T, E>;
  /** Get the success value - only available after isOk() check */
  getValue(): T;
}
/**
 * Union type of all AsyncResult states.
 * Use isOk(), isErr(), or isLoading() to narrow to specific state.
 */
type AsyncResult<T, E> = AsyncResultErr<T, E> | AsyncResultLoading<T, E> | AsyncResultOk<T, E>;
/**
 * Static factory methods for creating AsyncResult instances.
 * This pattern (same name for type and value) is intentional for ergonomic API.
 */
declare const AsyncResult: {
  /**
   * Create a failed AsyncResult with error
   */
  readonly err: <T, E>(error: E) => AsyncResultErr<T, E>;
  /**
   * Create an AsyncResult from an existing neverthrow Result
   */
  readonly fromResult: <T, E>(result: Result<T, E>) => AsyncResult<T, E>;
  /**
   * Create a loading AsyncResult
   */
  readonly loading: <T, E>() => AsyncResultLoading<T, E>;
  /**
   * Create a successful AsyncResult with data
   */
  readonly ok: <T, E>(value: T) => AsyncResultOk<T, E>;
};
//#endregion
//#region src/types/apiError.type.d.ts
interface ApiKnownErrorObject<TCode extends string = string> {
  code: TCode;
  detail: string;
  source?: {
    pointer: string;
  };
  status: string;
}
interface ApiUnknownErrorObject {
  code: string;
  detail: string;
  source?: {
    pointer: string;
  };
  status: string;
}
type ApiErrorObject<TCode extends string = string> = ApiKnownErrorObject<TCode> | ApiUnknownErrorObject;
interface ApiExpectedError<TCode extends string = string> {
  errors: ApiErrorObject<TCode>[];
}
type ApiUnexpectedError = Error;
type ApiError<TCode extends string = string> = ApiExpectedError<TCode> | ApiUnexpectedError;
type ApiResult<T, TCode extends string = string> = Result<T, ApiError<TCode>>;
type AsyncApiResult<T, TCode extends string = string> = AsyncResult<T, ApiError<TCode>>;
//#endregion
//#region src/composables/mutation/mutation.composable.d.ts
type RequestParams$1<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
  params: TParams;
} : TParams extends void ? {
  body: TReqData;
} : {
  body: TReqData;
  params: TParams;
};
interface UseMutationReturnType<TReqData, TResData, TParams = void, TErrorCode extends string = string> {
  /**
   * Whether mutation is loading
   * @deprecated - use `result.value.isLoading()` instead
   */
  isLoading: ComputedRef<boolean>;
  /**
   * Response data from the mutation
   * @deprecated - use `result.value.getValue()` instead
   */
  data: ComputedRef<TResData | null>;
  /**
   * Function to execute the mutation
   * @param data - Parameters and body for the mutation
   * @returns Promise with ApiResult containing either the response data or an error
   */
  execute: (data: RequestParams$1<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
  /**
   * Computed result of the mutation
   * Returns an AsyncResult with three states:
   * - loading: use `result.value.isLoading()`
   * - ok: use `result.value.isOk()` and `result.value.getValue()`
   * - err: use `result.value.isErr()` and `result.value.getError()`
   */
  result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
}
//#endregion
//#region src/types/sort.type.d.ts
declare enum SortDirection {
  ASC = "asc",
  DESC = "desc",
}
interface Sort<TKey$1 extends string = string> {
  direction: SortDirection;
  key: TKey$1;
}
//#endregion
//#region src/types/queryOptions.d.ts
interface QueryParams {
  filters?: Record<string, any>;
  search?: string;
  sort?: Sort[];
}
interface WithSearchQuery {
  search?: string | undefined;
}
interface WithSortQuery<TKeys extends string> {
  sort: Sort<TKeys>[];
}
interface WithFilterQuery<TFilters extends Record<string, any>> {
  filters?: TFilters;
}
interface WithStaticFilterQuery<TFilters extends Record<string, any>> {
  staticFilters: TFilters;
}
interface InfiniteQueryOptions<TParams> {
  params: { [K in keyof TParams]: Ref<TParams[K]> };
}
//#endregion
//#region src/types/pagination.type.d.ts
interface OffsetPaginationParams {
  limit: number;
  offset: number;
}
type OffsetPagination<T extends QueryParams = Record<string, never>> = {
  pagination: OffsetPaginationParams;
} & T;
interface KeysetPaginationParams {
  key?: any;
  limit: number;
}
type KeysetPagination<T extends QueryParams> = {
  pagination: KeysetPaginationParams;
} & T;
interface OffsetPaginationResponse<TData> {
  data: TData[];
  meta: {
    limit: number;
    offset: number;
    total: number;
  };
}
interface KeysetPaginationResponse<TData> {
  data: TData[];
  meta: {
    next: unknown;
  };
}
type OffsetPaginationResult<TData, TErrorCode extends string = string> = ApiResult<OffsetPaginationResponse<TData>, TErrorCode>;
type KeysetPaginationResult<TData, TErrorCode extends string = string> = ApiResult<KeysetPaginationResponse<TData>, TErrorCode>;
interface PaginatedDataDto<TSchema> {
  items: TSchema[];
  meta: {
    limit: number;
    offset: number;
    total: number;
  };
}
//#endregion
//#region src/composables/query/keysetInfiniteQuery.composable.d.ts
interface KeysetInfiniteQueryOptions<TData, TErrorCode extends string = string> {
  /**
   * The time in milliseconds after which the query will be considered stale
   * After this time, the query will be refetched automatically in the background when it is rendered or accessed
   * @default 0
   */
  staleTime?: number;
  /**
   * Whether the query is enabled
   * If false, the query will not be executed
   * @default true
   */
  isEnabled?: MaybeRef<boolean>;
  /**
   * Maximum number of items to fetch per page, default can be set in config
   * @default 20
   */
  limit?: number;
  /**
   * Function that will be called when query is executed
   * @returns Promise with response data
   */
  queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<TData, TErrorCode>>;
  /**
   * Query key associated with the query
   */
  queryKey: Record<string, unknown>;
}
interface UseKeysetInfiniteQueryReturnType<TData, TErrorCode extends string = string> {
  /**
   * Whether there is a next page available to fetch
   */
  hasNextPage: ComputedRef<boolean>;
  /**
   * Whether query has errored at least once
   * @deprecated - use `result.value.isErr()` instead
   */
  isError: ComputedRef<boolean>;
  /**
   * Whether query is currently fetching data, regardless of cache status
   */
  isFetching: ComputedRef<boolean>;
  /**
   * Whether query is currently fetching the next page
   */
  isFetchingNextPage: ComputedRef<boolean>;
  /**
   * Whether query is initially loading
   * @deprecated - use `result.value.isLoading()` instead
   */
  isLoading: ComputedRef<boolean>;
  /**
   * Whether query has been executed successfully
   * @deprecated - use `result.value.isOk()` instead
   */
  isSuccess: ComputedRef<boolean>;
  /**
   * Fetch the next page of results using the keyset cursor
   */
  fetchNextPage: () => Promise<void>;
  /**
   * Refetch the query
   */
  refetch: () => Promise<void>;
  /**
   * Computed result of the query containing all accumulated pages
   * Returns an AsyncResult with three states:
   * - loading: use `result.value.isLoading()`
   * - ok: use `result.value.isOk()` and `result.value.getValue()`
   * - err: use `result.value.isErr()` and `result.value.getError()`
   *
   * Use `result.value.match({ loading, ok, err })` for exhaustive handling
   */
  result: ComputedRef<AsyncResult<KeysetPaginationResponse<TData>, ApiError<TErrorCode>>>;
}
//#endregion
//#region src/composables/query/offsetInfiniteQuery.composable.d.ts
interface OffsetInfiniteQueryOptions<TData, TErrorCode extends string = string> {
  /**
   * The time in milliseconds after which the query will be considered stale
   * After this time, the query will be refetched automatically in the background when it is rendered or accessed
   * @default 0
   */
  staleTime?: number;
  /**
   * Whether the query is enabled
   * If false, the query will not be executed
   * @default true
   */
  isEnabled?: MaybeRef<boolean>;
  /**
   * Maximum number of items to fetch per page, default can be set in config
   * @default 20
   */
  limit?: number;
  /**
   * Function that will be called when query is executed
   * @returns Promise with response data
   */
  queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<TData, TErrorCode>>;
  /**
   * Query key associated with the query
   */
  queryKey: Record<string, unknown>;
}
interface UseOffsetInfiniteQueryReturnType<TData, TErrorCode extends string = string> {
  /**
   * Whether there is a next page available to fetch
   */
  hasNextPage: ComputedRef<boolean>;
  /**
   * Whether query has errored at least once
   * @deprecated - use `result.value.isErr()` instead
   */
  isError: ComputedRef<boolean>;
  /**
   * Whether query is currently fetching data, regardless of cache status
   */
  isFetching: ComputedRef<boolean>;
  /**
   * Whether query is currently fetching the next page
   */
  isFetchingNextPage: ComputedRef<boolean>;
  /**
   * Whether query is initially loading
   * @deprecated - use `result.value.isLoading()` instead
   */
  isLoading: ComputedRef<boolean>;
  /**
   * Whether query has been executed successfully
   * @deprecated - use `result.value.isOk()` instead
   */
  isSuccess: ComputedRef<boolean>;
  /**
   * Fetch the next page of results using offset-based pagination
   */
  fetchNextPage: () => Promise<void>;
  /**
   * Refetch the query
   */
  refetch: () => Promise<void>;
  /**
   * Computed result of the query containing all accumulated pages
   * Returns an AsyncResult with three states:
   * - loading: use `result.value.isLoading()`
   * - ok: use `result.value.isOk()` and `result.value.getValue()`
   * - err: use `result.value.isErr()` and `result.value.getError()`
   *
   * Use `result.value.match({ loading, ok, err })` for exhaustive handling
   */
  result: ComputedRef<AsyncResult<OffsetPaginationResponse<TData>, ApiError<TErrorCode>>>;
}
//#endregion
//#region src/composables/query/query.composable.d.ts
interface UseQueryOptions<TResData, TErrorCode extends string = string> {
  /**
   * The time in milliseconds after which the query will be considered stale
   * After this time, the query will be refetched automatically in the background when it is rendered or accessed
   * @default 0
   */
  staleTime?: number;
  /**
   * Whether to enable debug mode
   * When enabled, the query key and parameters will be logged to the console
   * @default false
   */
  isDebug?: boolean;
  /**
   * Whether the query is enabled
   * If false, the query will not be executed
   * @default true
   */
  isEnabled?: MaybeRef<boolean>;
  /**
   * Function that will be called when query is executed
   * @returns Promise with response data
   */
  queryFn: () => Promise<ApiResult<TResData, TErrorCode>>;
  /**
   * Query key associated with the query
   */
  queryKey: Record<string, unknown>;
}
interface UseQueryReturnType<TResData, TErrorCode extends string = string> {
  /**
   * Whether query has errored at least once
   * @deprecated - use `result.value.isErr()` instead
   */
  isError: ComputedRef<boolean>;
  /**
   * Whether query is currently fetching data, regardless of cache status
   */
  isFetching: ComputedRef<boolean>;
  /**
   * Whether query is initially loading
   * @deprecated - use `result.value.isLoading()` instead
   */
  isLoading: ComputedRef<boolean>;
  /**
   * Whether query has been executed successfully
   * @deprecated - use `result.value.isOk()` instead
   */
  isSuccess: ComputedRef<boolean>;
  /**
   * Refetch the query
   */
  refetch: () => Promise<void>;
  /**
   * Computed result of the query
   * Returns an AsyncResult with three states:
   * - loading: use `result.value.isLoading()`
   * - ok: use `result.value.isOk()` and `result.value.getValue()`
   * - err: use `result.value.isErr()` and `result.value.getError()`
   *
   * Use `result.value.match({ loading, ok, err })` for exhaustive handling
   */
  result: ComputedRef<AsyncResult<TResData, ApiError<TErrorCode>>>;
}
//#endregion
//#region src/config/config.d.ts
/**
 * Initialize the API utilities with a QueryClient.
 * Call this once during app setup (e.g. in a plugin or main.ts).
 *
 * After calling this, `createApiUtils()` can be called without options.
 *
 * @example
 * ```typescript
 * import { initializeApiUtils } from '@wisemen/vue-core-api-utils'
 *
 * const queryClient = new QueryClient()
 * initializeApiUtils(queryClient)
 *
 * // Then in your api lib:
 * export const { useQuery, useMutation, ... } = createApiUtils<MyQueryKeys>()
 * ```
 */
declare function initializeApiUtils(queryClient: QueryClient$1): void;
/**
 * @internal
 */
declare function getQueryClient(): QueryClient$1;
interface QueryConfig {
  prefetchStaleTime: number;
  limit: number;
}
declare function setQueryConfig(config: Partial<QueryConfig>): void;
//#endregion
//#region src/types/queryKeys.type.d.ts
/**
 * Generic helper types for libraries/factories that want to infer query key typing
 * from a user-provided config object (instead of relying on module augmentation).
 */
/**
 * Extract the entity type from a query-keys config for a specific key.
 */
type QueryKeyEntityFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
  entity: infer E;
} ? E : never : never;
/**
 * Extract the params type from a query-keys config for a specific key.
 * Automatically wraps each param in Ref for reactivity.
 */
type QueryKeyParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
  params: infer P;
} ? { [K in keyof P]: Ref<P[K]> } : void : never;
/**
 * Extract the raw params type from a query-keys config for a specific key (unwrapped from Computed).
 * Used for optimistic updates which accept plain values.
 */
type QueryKeyRawParamsFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = TKey$1 extends keyof TQueryKeys ? TQueryKeys[TKey$1] extends {
  params: infer P;
} ? P : void : never;
/**
 * Get all keys that have an associated entity in a query-keys config.
 */
type QueryKeysWithEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
  entity: any;
} ? K : never }[keyof TQueryKeys]) & string;
//#endregion
//#region src/factory/createApiUtils.types.d.ts
/**
 * Helper type to build the invalidation config for a specific query key
 * Maps the query key's params to optional parameter extractors
 */
type QueryKeyInvalidationConfig<TQueryKeys extends object, TKey$1 extends keyof TQueryKeys, TParams, TResData> = QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string> extends void ? {} : QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string> extends object ? { [ParamKey in keyof QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string>]?: (params: TParams, data: TResData) => QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1 & string>[ParamKey] } : {};
type QueryKeysWithArrayEntityFromConfig<TQueryKeys extends object> = ({ [K in keyof TQueryKeys]: TQueryKeys[K] extends {
  entity: any[];
} ? K : never }[keyof TQueryKeys]) & string;
type QueryKeyArrayItemFromConfig<TQueryKeys extends object, TKey$1 extends PropertyKey> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1> extends (infer TItem)[] ? TItem : never;
type ApiUseQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
  staleTime?: number;
  isDebug?: boolean;
  isEnabled?: MaybeRef<boolean>;
  queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
  params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
} : {
  params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
});
type ApiUsePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
  staleTime?: number;
  queryFn: () => Promise<ApiResult<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
  params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
} : {
  params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
});
type ApiUseOffsetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
  staleTime?: number;
  isEnabled?: MaybeRef<boolean>;
  limit?: number;
  queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
  params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
} : {
  params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
});
type ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
  staleTime?: number;
  limit?: number;
  queryFn: (paginationParams: OffsetPaginationParams) => Promise<OffsetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
  params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
} : {
  params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
});
type ApiUseKeysetInfiniteQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
  staleTime?: number;
  isEnabled?: MaybeRef<boolean>;
  limit?: number;
  queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
  params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
} : {
  params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
});
type ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = {
  staleTime?: number;
  limit?: number;
  queryFn: (paginationParams: KeysetPaginationParams) => Promise<KeysetPaginationResult<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>>;
} & (QueryKeyParamsFromConfig<TQueryKeys, TKey$1> extends void ? {
  params?: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
} : {
  params: QueryKeyParamsFromConfig<TQueryKeys, TKey$1>;
});
type RequestParams<TReqData, TParams> = TReqData extends void ? TParams extends void ? void : {
  params: TParams;
} : TParams extends void ? {
  body: TReqData;
} : {
  body: TReqData;
  params: TParams;
};
interface ApiUseMutationOptions<TQueryKeys extends object, TReqData, TResData, TParams = void, TErrorCode extends string = string> {
  /**
   * Whether to enable debug mode
   */
  isDebug?: boolean;
  /**
   * Function that will be called to perform the mutation
   * @param options - Parameters and body for the mutation
   * @returns Promise with ApiResult containing either the response data or an error
   */
  queryFn: (options: RequestParams<TReqData, TParams>) => Promise<ApiResult<TResData, TErrorCode>>;
  /**
   * Query keys which should be invalidated after mutation is successful
   * Each key is optional and maps to the query key's specific parameters
   * @example
   * ```typescript
   * queryKeysToInvalidate: {
   *   userDetail: {
   *     userUuid: (params, result) => params.userUuid,
   *   },
   *   userList: {},
   * }
   * ```
   */
  queryKeysToInvalidate?: { [TKey in keyof TQueryKeys]?: QueryKeyInvalidationConfig<TQueryKeys, TKey, TParams, TResData> };
}
//#endregion
//#region src/factory/createApiInfiniteQueryUtils.d.ts
interface CreateApiInfiniteQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
  useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
  useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
}
type ApiUseKeysetInfiniteQueryReturnType<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
type ApiUseOffsetInfiniteQueryReturnType<TQueryKeys extends object, TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>, TErrorCode extends string = string> = UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
//#endregion
//#region src/factory/createApiMutationUtils.d.ts
interface CreateApiMutationUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
  useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams, TErrorCode>) => UseMutationReturnType<TReqData, TResData, TParams, TErrorCode>;
}
//#endregion
//#region src/factory/createApiPrefetchInfiniteQueryUtils.d.ts
interface CreateApiPrefetchInfiniteQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
  usePrefetchKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
    execute: () => Promise<void>;
  };
  usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
    execute: () => Promise<void>;
  };
}
//#endregion
//#region src/factory/createApiPrefetchQueryUtils.d.ts
interface CreateApiPrefetchQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
  usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
    execute: () => Promise<void>;
  };
}
//#endregion
//#region src/utils/query-client/queryClient.d.ts
/**
 * Helper type to extract the item type from an entity (array item or entity itself)
 */
type EntityItem<TEntity> = TEntity extends any[] ? TEntity[number] : TEntity;
/**
 * Options for type-safe query client update
 */
interface QueryClientUpdateOptions<TEntity> {
  /**
   * Predicate function that receives the current item and returns true if it should be updated
   */
  by: (item: EntityItem<TEntity>) => boolean;
  /**
   * Function that receives the current item and returns the updated item
   */
  value: (item: EntityItem<TEntity>) => EntityItem<TEntity>;
}
/**
 * Result of an update operation, providing a rollback function
 */
interface QueryClientUpdateResult {
  /**
   * Reverts the cache entries affected by this update to their state before the update was applied.
   * Safe to call multiple times (subsequent calls are no-ops).
   */
  rollback: () => void;
}
/**
 * QueryClient utility class for type-safe query operations
 */
declare class QueryClient<TQueryKeys extends object> {
  private readonly queryClient;
  constructor(queryClient: QueryClient$1);
  /**
   * Extract the raw entity from AsyncResult data
   */
  private extractEntityFromAsyncResult;
  private hasDataArray;
  private isInfiniteDataLike;
  /**
   * Determine if an item should be updated
   */
  private shouldUpdateItem;
  /**
   * Internal method to update entity based on the "by" option
   */
  private updateEntity;
  private updateInfinitePageValue;
  /**
   * Wrap a raw entity in an AsyncResult (preserving ok state)
   */
  private wrapEntityInAsyncResult;
  /**
   * Get raw entity data from the query cache
   * Automatically extracts the entity from AsyncResult wrapper
   *
   * When using just a key string:
   * - By default (isExact=false), returns ALL queries with that key as first element
   * - With isExact=true, returns only the query stored as [key]
   *
   * @example
   * ```typescript
   * // Get all userDetail queries (returns array)
   * const allUsers = queryClient.get('userDetail')
   *
   * // Get exact query stored as ['userDetail']
   * const exactUser = queryClient.get('userDetail', { isExact: true })
   *
   * // Get specific userDetail query with params
   * const user = queryClient.get(['userDetail', { userUuid: '123' }] as const)
   * ```
   */
  get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, options?: {
    isExact?: false;
  }): QueryKeyEntityFromConfig<TQueryKeys, TKey$1>[];
  get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, options: {
    isExact: true;
  }): QueryKeyEntityFromConfig<TQueryKeys, TKey$1> | null;
  get<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>]): QueryKeyEntityFromConfig<TQueryKeys, TKey$1> | null;
  /**
   * Invalidate queries to trigger a refetch
   *
   * When using just the key, invalidates ALL queries with that key
   * When using key + params tuple, invalidates SPECIFIC query
   *
   * @example
   * ```typescript
   * // Invalidate all userDetail queries
   * await queryClient.invalidate('userDetail')
   *
   * // Invalidate specific query
   * await queryClient.invalidate(['userDetail', { userUuid: '123' }] as const)
   * ```
   */
  invalidate<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1): Promise<void>;
  invalidate<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(keyTuple: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>]): Promise<void>;
  /**
   * Set raw entity data in the query cache for a specific query
   * Automatically wraps the entity in AsyncResult
   *
   * Both formats set a single query - just with different key representations:
   * - 'userDetail' sets the query with key ['userDetail']
   * - ['userDetail', { userUuid: '123' }] sets the query with that exact key
   *
   * @example
   * ```typescript
   * // Set query with just the key
   * queryClient.set('userDetail', userData)
   *
   * // Set query with key + params
   * queryClient.set(['userDetail', { userUuid: '123' }] as const, userData)
   * ```
   */
  set<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: TKey$1, entity: QueryKeyEntityFromConfig<TQueryKeys, TKey$1>): void;
  set<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(queryKey: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>], entity: QueryKeyEntityFromConfig<TQueryKeys, TKey$1>): void;
  /**
   * Update entity data in the query cache
   *
   * When using just the key, updates ALL queries with that key
   * When using key + params tuple, updates SPECIFIC query
   *
   * @example
   * ```typescript
   * // Update a specific user by id
   * const { rollback } = queryClient.update('userDetail', {
   *   by: (user) => user.id === '123',
   *   value: (user) => ({ ...user, name: 'John Doe' })
   * })
   *
   * // Revert if the mutation fails
   * rollback()
   *
   * // Update all electronics products to out of stock
   * queryClient.update('productList', {
   *   by: (product) => product.category === 'electronics',
   *   value: (product) => ({ ...product, inStock: false })
   * })
   * ```
   */
  update<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey$1> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>(key: TKey$1, options: QueryClientUpdateOptions<TEntity>): QueryClientUpdateResult;
  update<TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>, TEntity extends QueryKeyEntityFromConfig<TQueryKeys, TKey$1> = QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>(keyTuple: readonly [TKey$1, Partial<QueryKeyRawParamsFromConfig<TQueryKeys, TKey$1>>], options: QueryClientUpdateOptions<TEntity>): QueryClientUpdateResult;
}
//#endregion
//#region src/factory/createApiQueryClientUtils.d.ts
interface CreateApiQueryClientUtilsReturnType<TQueryKeys extends object> {
  useQueryClient: () => QueryClient<TQueryKeys>;
}
//#endregion
//#region src/factory/createApiQueryUtils.d.ts
interface CreateApiQueryUtilsReturnType<TQueryKeys extends object, TErrorCode extends string = string> {
  useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>>;
}
//#endregion
//#region src/factory/createApiUtils.d.ts
/**
 * Factory that creates typed composables based on a user-provided query-keys config.
 *
 * Requires `initializeApiUtils(queryClient)` to be called first.
 *
 * @example
 * ```typescript
 * // In app setup (plugin or main.ts):
 * initializeApiUtils(queryClient)
 *
 * // In your api lib:
 * export const { useQuery, useMutation, useQueryClient } = createApiUtils<MyQueryKeys>()
 * ```
 */
declare function createApiUtils<TQueryKeys extends object, TErrorCode extends string = string>(): {
  useQueryClient: () => QueryClient<TQueryKeys>;
  useMutation: <TReqData = void, TResData = void, TParams = void>(options: ApiUseMutationOptions<TQueryKeys, TReqData, TResData, TParams, TErrorCode>) => UseMutationReturnType<TReqData, TResData, TParams, TErrorCode>;
  useKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseKeysetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
  useOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfiniteQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseOffsetInfiniteQueryReturnType<QueryKeyArrayItemFromConfig<TQueryKeys, TKey$1>, TErrorCode>;
  usePrefetchKeysetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseKeysetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
    execute: () => Promise<void>;
  };
  usePrefetchOffsetInfiniteQuery: <TKey$1 extends QueryKeysWithArrayEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseOffsetInfinitePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
    execute: () => Promise<void>;
  };
  usePrefetchQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUsePrefetchQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => {
    execute: () => Promise<void>;
  };
  useQuery: <TKey$1 extends QueryKeysWithEntityFromConfig<TQueryKeys>>(key: TKey$1, queryOptions: ApiUseQueryOptions<TQueryKeys, TKey$1, TErrorCode>) => UseQueryReturnType<QueryKeyEntityFromConfig<TQueryKeys, TKey$1>, string>;
};
//#endregion
//#region src/plugin/apiUtilsPlugin.d.ts
/**
 * Create a Vue plugin that sets up TanStack Query and initializes API utilities.
 *
 * This plugin handles:
 * - Creating a QueryClient with the provided config
 * - Installing VueQueryPlugin on the app
 * - Initializing the global QueryClient for api-utils
 *
 * @example
 * ```typescript
 * import { apiUtilsPlugin } from '@wisemen/vue-core-api-utils'
 * import { vueQueryClientConfig } from '@wisemen/vue-core-configs'
 *
 * app.use(apiUtilsPlugin(vueQueryClientConfig()))
 * ```
 *
 * @param config - QueryClient configuration
 * @returns A Vue plugin that can be used with app.use()
 */
declare function apiUtilsPlugin(config: QueryClientConfig): {
  install: (app: App<any>) => void;
};
//#endregion
//#region src/utils/sort/sort.utils.d.ts
declare class SortUtil {
  static toDto<SortKey extends string, QueryKey>(sort: Sort<SortKey>[], sortKeyMap: Record<SortKey, QueryKey>): {
    key: QueryKey;
    order: SortDirection;
  }[];
}
//#endregion
export { type ApiUnexpectedError, type ApiUnknownErrorObject, type ApiUseKeysetInfinitePrefetchQueryOptions, type ApiUseKeysetInfiniteQueryOptions, type ApiUseKeysetInfiniteQueryReturnType, type ApiUseMutationOptions, type ApiUseOffsetInfinitePrefetchQueryOptions, type ApiUseOffsetInfiniteQueryOptions, type ApiUseOffsetInfiniteQueryReturnType, type ApiUsePrefetchQueryOptions, type ApiUseQueryOptions, AsyncResult, AsyncResultErr, AsyncResultLoading, AsyncResultOk, type CreateApiInfiniteQueryUtilsReturnType, type CreateApiMutationUtilsReturnType, type CreateApiPrefetchInfiniteQueryUtilsReturnType, type CreateApiPrefetchQueryUtilsReturnType, type CreateApiQueryClientUtilsReturnType, type CreateApiQueryUtilsReturnType, type InfiniteQueryOptions, type KeysetInfiniteQueryOptions, type KeysetPagination, type KeysetPaginationParams, type KeysetPaginationResponse, type OffsetInfiniteQueryOptions, type OffsetPagination, type OffsetPaginationParams, type OffsetPaginationResponse, type PaginatedDataDto, QueryClient, type QueryClientUpdateOptions, type QueryClientUpdateResult, type QueryConfig, type QueryKeyArrayItemFromConfig, type QueryKeysWithArrayEntityFromConfig, type QueryParams, type Sort, SortDirection, SortUtil, type TanstackQueryClient, type UseKeysetInfiniteQueryReturnType, type UseMutationReturnType, type UseOffsetInfiniteQueryReturnType, type UseQueryOptions, type UseQueryReturnType, type WithFilterQuery, type WithSearchQuery, type WithSortQuery, type WithStaticFilterQuery, apiUtilsPlugin, createApiUtils, getQueryClient as getTanstackQueryClient, initializeApiUtils, setQueryConfig, type ApiError as "~ApiError", type ApiErrorObject as "~ApiErrorObject", type ApiExpectedError as "~ApiExpectedError", type ApiKnownErrorObject as "~ApiKnownErrorObject", type ApiResult as "~ApiResult", type AsyncApiResult as "~AsyncApiResult", type KeysetPaginationResult as "~KeysetPaginationResult", type OffsetPaginationResult as "~OffsetPaginationResult" };