"use strict";
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.DelaySession = void 0;
class DelaySession {
    constructor(baseDebounceTime, expectedTotalTime, providerInvocationTime = Date.now()) {
        this.baseDebounceTime = baseDebounceTime;
        this.expectedTotalTime = expectedTotalTime;
        this.providerInvocationTime = providerInvocationTime;
        this.extraDebounce = 0;
    }
    setExtraDebounce(extraDebounce) {
        this.extraDebounce = extraDebounce;
    }
    setBaseDebounceTime(baseDebounceTime) {
        this.baseDebounceTime = baseDebounceTime;
    }
    setExpectedTotalTime(expectedTotalTime) {
        this.expectedTotalTime = expectedTotalTime;
    }
    getDebounceTime() {
        const expectedDebounceTime = this.expectedTotalTime === undefined
            ? this.baseDebounceTime
            : Math.min(this.baseDebounceTime, this.expectedTotalTime);
        const expectedDebounceTimeWithExtras = expectedDebounceTime + this.extraDebounce;
        const timeAlreadySpent = Date.now() - this.providerInvocationTime;
        const actualDebounceTime = Math.max(0, expectedDebounceTimeWithExtras - timeAlreadySpent);
        return actualDebounceTime;
    }
    getArtificialDelay() {
        if (this.expectedTotalTime === undefined) {
            return 0;
        }
        const timeAlreadySpent = Date.now() - this.providerInvocationTime;
        const delay = Math.max(0, this.expectedTotalTime - timeAlreadySpent);
        return delay;
    }
}
exports.DelaySession = DelaySession;
//# sourceMappingURL=delay.js.map