import { BaseRequest } from './base.request';
export class Request extends BaseRequest {
    constructor(dynamoRx, modelClazz, tableName) {
        super(dynamoRx, modelClazz, tableName);
        this.limit(Request.DEFAULT_LIMIT);
    }
    /**
     *
     * @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}
     */
    exclusiveStartKey(key) {
        if (key) {
            this.params.ExclusiveStartKey = key;
        }
        else {
            delete this.params.ExclusiveStartKey;
        }
        return this;
    }
    index(indexName) {
        const 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;
    }
    limit(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;
//# sourceMappingURL=request.model.js.map