import * as tslib_1 from "tslib";
import { BaseRequest } from './base.request';
var Request = /** @class */ (function (_super) {
    tslib_1.__extends(Request, _super);
    function Request(dynamoRx, modelClazz, tableName) {
        var _this = _super.call(this, dynamoRx, modelClazz, tableName) || this;
        _this.limit(Request.DEFAULT_LIMIT);
        return _this;
    }
    /**
     *
     * @param key A map representing the start id which is included in next call, if null is delivered
     * startKey will be removed from params
     * @returns {Request}
     */
    Request.prototype.exclusiveStartKey = function (key) {
        if (key) {
            this.params.ExclusiveStartKey = key;
        }
        else {
            delete this.params.ExclusiveStartKey;
        }
        return this;
    };
    Request.prototype.index = function (indexName) {
        var index = this.metadata.getIndex(indexName);
        if (index) {
            this.params.IndexName = indexName;
        }
        else {
            throw new Error("there is no index with name <" + indexName + "> defined for model " + this.modelClazz.name);
        }
        return this;
    };
    Request.prototype.limit = function (limit) {
        if (limit === Request.INFINITE_LIMIT) {
            delete this.params.Limit;
        }
        else {
            if (limit !== null && limit !== undefined && limit > 0) {
                this.params.Limit = limit;
            }
            else {
                throw new Error('limit must be a valid positive number');
            }
        }
        return this;
    };
    Request.DEFAULT_LIMIT = 10;
    Request.INFINITE_LIMIT = -1;
    return Request;
}(BaseRequest));
export { Request };
//# sourceMappingURL=request.model.js.map