// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { parseOrderByQueryContinuationToken } from "../../documents/ContinuationToken/OrderByQueryContinuationToken.js";
/**
 * Strategy for processing ORDER BY queries
 * @hidden
 */
export class OrderByQueryProcessingStrategy {
    sortOrders;
    constructor(sortOrders) {
        this.sortOrders = sortOrders;
    }
    /**
     * Creates additional query info from ORDER BY continuation token
     */
    createAdditionalQueryInfo(parsedToken) {
        const orderByToken = parsedToken;
        const info = {};
        if (orderByToken.orderByItems)
            info.orderByItems = orderByToken.orderByItems;
        if (orderByToken.documentRid)
            info.rid = orderByToken.documentRid;
        return Object.keys(info).length > 0 ? info : undefined;
    }
    /**
     * Creates filter context for ORDER BY continuation token processing
     */
    createFilterContext(parsedToken) {
        const orderByToken = parsedToken;
        return {
            orderByItems: orderByToken.orderByItems,
            rid: orderByToken.documentRid,
            skipCount: orderByToken.skipCount,
            sortOrders: this.sortOrders,
        };
    }
    /**
     * For ORDER BY queries, only apply filter to the target partition (last range in continuation)
     */
    getPartitionFilterContext(filterContext, targetPartitionId, partitionTargetRangeId) {
        if (!filterContext)
            return undefined;
        const isTargetPartition = targetPartitionId === partitionTargetRangeId;
        return isTargetPartition ? filterContext : undefined;
    }
    /**
     * Parses ORDER BY continuation token
     */
    parseContinuationToken(continuationToken) {
        return parseOrderByQueryContinuationToken(continuationToken);
    }
}
//# sourceMappingURL=OrderByQueryProcessingStrategy.js.map