import type { ObjectSet, ObjectTypeDefinition, Osdk, PageResult } from "@osdk/api";
import type { Connectable, Observable, Subscription } from "rxjs";
import type { CommonObserveOptions, Status } from "../../ObservableClient/common.js";
import type { BatchContext } from "../BatchContext.js";
import { type CacheKey } from "../CacheKey.js";
import type { Canonical } from "../Canonical.js";
import type { Entry } from "../Layer.js";
import { type ObjectCacheKey } from "../object/ObjectCacheKey.js";
import { Query } from "../Query.js";
import type { Rdp } from "../RdpCanonicalizer.js";
import type { SortingStrategy } from "../sorting/SortingStrategy.js";
import type { SubjectPayload } from "../SubjectPayload.js";
import type { ObjectUpdate } from "../types/ObjectUpdate.js";
import type { CollectionConnectableParams, CollectionStorageData } from "./BaseCollectionQuery.js";
/**
* Base class for collection-based queries (lists and links)
* Provides common functionality for working with collections of objects
*/
export declare abstract class BaseListQuery<
	KEY extends CacheKey<any, CollectionStorageData, any, any>,
	PAYLOAD,
	O extends CommonObserveOptions
> extends Query<KEY, PAYLOAD, O> {
	#private;
	/**
	* The sorting strategy to use for this collection
	* @protected
	*/
	protected sortingStrategy: SortingStrategy;
	/**
	* Get RDP configuration from the cache key
	*/
	get rdpConfig(): Canonical<Rdp> | null;
	/**
	* Token for the next page of results
	* @protected
	*/
	protected nextPageToken?: string;
	/**
	* Promise tracking an in-progress page fetch
	* @protected
	*/
	protected pendingPageFetch?: Promise<void>;
	/**
	* Standard method to update a list of objects
	* Handles common list update patterns for both ListQuery and SpecificLinkQuery
	*
	* @param items Objects or cache keys to add to the list
	* @param status Status to set for the list
	* @param batch Batch context to use
	* @param append Whether to append to the existing list or replace it
	* @returns The updated entry
	*/
	_updateList<T extends ObjectCacheKey | Osdk.Instance<any>>(items: T[], status: Status, batch: BatchContext, append?: boolean): Entry<KEY>;
	/**
	* Common implementation for writing to store for collection-based queries
	* @param data The collection data to write to the store
	* @param status The status to set
	* @param batch The batch context
	*/
	writeToStore(data: CollectionStorageData, status: Status, batch: BatchContext): Entry<KEY>;
	/**
	* Register changes to the cache based on the specific collection type
	* Implemented by subclasses to handle specific change registration
	*/
	protected abstract registerCacheChanges(batch: BatchContext): void;
	_dispose(): void;
	/**
	* Creates a payload from collection parameters
	* Default implementation that covers common fields for all collection types
	* Subclasses may override to add type-specific fields if needed
	*
	* @param params Common collection parameters
	* @returns A typed payload for the specific collection type
	*/
	protected createPayload(params: CollectionConnectableParams): PAYLOAD;
	/**
	* Creates a connectable observable for this collection
	* Common implementation shared by all collection types
	*
	* @param subject The subject to connect to
	* @returns A connectable observable of the collection's payload type
	*/
	protected _createConnectable(subject: Observable<SubjectPayload<KEY>>): Connectable<PAYLOAD>;
	/**
	* @override Reset pagination state before a fetch
	*/
	protected _preFetch(): void;
	/**
	* Common fetchMore implementation for pagination
	* Handles pending request management and loading states
	*/
	fetchMore: () => Promise<void>;
	/**
	* Minimum number of results to load initially
	* May be overridden by subclasses for specific collection types
	* @protected
	*/
	protected minResultsToLoad: number;
	/**
	* Common _fetchAndStore implementation for pagination
	* Uses fetchPageAndUpdate to load the initial set of data
	* Will load multiple pages if necessary to reach minResultsToLoad
	*/
	protected _fetchAndStore(): Promise<void>;
	/**
	* Template method for fetching a page of data and updating the store
	* Provides common error handling and abort signal checking
	*
	* @param status The status to set for the entry
	* @param signal Optional AbortSignal for cancellation
	* @returns A promise that resolves to the updated entry or undefined if aborted
	*/
	protected fetchPageAndUpdate(status: Status, signal: AbortSignal | undefined): Promise<Entry<KEY> | undefined>;
	/**
	* Abstract method that subclasses implement for their specific data fetching logic
	*
	* @param signal Optional AbortSignal for cancellation
	* @returns A promise that resolves to the fetched data
	*/
	protected abstract fetchPageData(signal: AbortSignal | undefined): Promise<PageResult<Osdk.Instance<any>>>;
	/**
	* Handle fetch errors by setting appropriate error state
	* Default implementation that subclasses can override
	*
	* @param error The error that occurred
	* @param status The intended status if successful
	* @param batch The batch context to use
	* @returns The updated entry with error status
	*/
	protected handleFetchError(_error: unknown, _status: Status, batch: BatchContext): Entry<KEY>;
	/**
	* Sort the collection items using the configured sorting strategy
	* @param objectCacheKeys - The cache keys to sort
	* @param batch - The batch context
	* @returns Sorted array of cache keys
	*/
	protected _sortCacheKeys(objectCacheKeys: ObjectCacheKey[], batch: BatchContext): ObjectCacheKey[];
	/**
	* Unified method for updating collection data in the store
	* Handles storing, sorting, deduplication, and reference counting
	*
	* @param items - Either object cache keys or object instances to update
	* @param options - Configuration options for the update
	* @param batch - The batch context to use
	* @returns The updated entry
	*/
	protected updateCollection<T extends ObjectCacheKey | Osdk.Instance<any>>(items: T[], options: {
		append?: boolean
		status: Status
	}, batch: BatchContext): Entry<KEY>;
	/**
	* Create standard websocket subscription handlers for an ObjectSet.
	* Subclasses can override individual handlers for custom behavior.
	*
	* @param objectSet The ObjectSet to subscribe to
	* @param sub The parent subscription to add cleanup to
	* @param methodName The method name for logging purposes
	*/
	protected createWebsocketSubscription(objectSet: ObjectSet<any>, sub: Subscription, methodName?: string): void;
	/**
	* Handler called when websocket subscription is successfully established.
	*/
	protected onOswSuccessfulSubscription(): void;
	/**
	* Handler called when subscribed data becomes out of date.
	*/
	protected onOswOutOfDate(): void;
	/**
	* Handler called when websocket subscription encounters an error.
	*/
	protected onOswError(errors: {
		subscriptionClosed: boolean
		error: unknown
	}): void;
	/**
	* Handler called when an object in the subscribed set is added or updated.
	* Default implementation stores the object with RDP config if available.
	*
	* @param update The object update notification
	*/
	protected onOswChange({ object, state }: ObjectUpdate<ObjectTypeDefinition, string>): void;
	/**
	* Handler called when an object is removed from the subscribed set.
	* Default implementation deletes the object from cache.
	* ListQuery overrides this for list-specific removal logic.
	*
	* @param object The removed object
	*/
	protected onOswRemoved(object: Osdk.Instance<ObjectTypeDefinition, never, string, {}>): void;
}
