var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import Guard from "../../guard";
import { QueryResultPagingManager } from "./query-result-paging-manager";
export class LoadingQueryIteratorBase {
    constructor(query, loadConfiguration, result) {
        Guard.notNullOrUndefined(query);
        Guard.notNullOrUndefined(loadConfiguration);
        //TODO: Make a deep clone?
        this._query = query;
        this._loadConfiguration = loadConfiguration;
        if (result != null) {
            this.current = result;
        }
    }
    canMovePrevious() {
        return QueryResultPagingManager.canMovePrevious(this.current);
    }
    canMoveNext() {
        return QueryResultPagingManager.canMoveNext(this.current);
    }
    movePreviousAsync() {
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.canMovePrevious())
                return false;
            this._query.skip = QueryResultPagingManager.getOffsetPreviousPage(this.current);
            this.current = yield this.getResultAsync(this._query, this._loadConfiguration);
            return true;
        });
    }
    moveNextAsync() {
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.canMoveNext())
                return false;
            this._query.skip = QueryResultPagingManager.getOffsetNextPage(this.current);
            this.current = yield this.getResultAsync(this._query, this._loadConfiguration);
            return true;
        });
    }
    reset() {
        this.current = null;
    }
}
//# sourceMappingURL=loading-query-iterator.js.map