import { applyLookupNumericColumnWriteTailPatch, } from './operation-lookup-planner.js';
export function planOperationLookupNumericWrites(request) {
    const exact = !request.isRestore &&
        request.hasExactLookupDependents &&
        !request.hasAggregateDependents &&
        request.oldExactLookupNumber !== undefined &&
        request.newExactLookupNumber !== undefined
        ? request.planner.planExactLookupNumericColumnWrite(request.sheetId, request.col, request.row, request.oldExactLookupNumber, request.newExactLookupNumber)
        : undefined;
    const sorted = !request.isRestore &&
        request.hasSortedLookupDependents &&
        !request.hasAggregateDependents &&
        request.oldApproximateLookupNumber !== undefined &&
        request.newApproximateLookupNumber !== undefined
        ? request.planner.planApproximateLookupNumericColumnWrite(request.sheetId, request.sheetName, request.col, request.row, request.oldApproximateLookupNumber, request.newApproximateLookupNumber)
        : undefined;
    const exactHandled = exact?.handled === true;
    const sortedHandled = sorted?.handled === true;
    return {
        exact,
        sorted,
        exactHandled,
        sortedHandled,
        needsLookupValueRead: request.hasAggregateDependents ||
            (request.hasExactLookupDependents && !exactHandled) ||
            (request.hasSortedLookupDependents && !sortedHandled),
        handledLookupDependents: (request.hasExactLookupDependents && exactHandled) || (request.hasSortedLookupDependents && sortedHandled),
    };
}
export function applyOperationLookupNumericWriteTailPatches(plans, request) {
    let exact = false;
    let sorted = false;
    if (request.oldExactLookupNumber !== undefined && request.newExactLookupNumber !== undefined) {
        exact = applyLookupNumericColumnWriteTailPatch(plans.exact, {
            row: request.row,
            oldNumeric: request.oldExactLookupNumber,
            newNumeric: request.newExactLookupNumber,
            columnVersion: request.columnVersionAfterWrite,
        });
    }
    if (request.oldApproximateLookupNumber !== undefined && request.newApproximateLookupNumber !== undefined) {
        sorted = applyLookupNumericColumnWriteTailPatch(plans.sorted, {
            row: request.row,
            oldNumeric: request.oldApproximateLookupNumber,
            newNumeric: request.newApproximateLookupNumber,
            columnVersion: request.columnVersionAfterWrite,
        });
    }
    return { exact, sorted };
}
//# sourceMappingURL=operation-lookup-write-plans.js.map