import * as tslib_1 from "tslib";
import { map } from 'rxjs/operators';
import { fetchAll } from '../../../helper';
import { Mapper } from '../../../mapper/mapper';
import { and } from '../../expression/logical-operator/and.function';
import { ParamUtil } from '../../expression/param-util';
import { RequestExpressionBuilder } from '../../expression/request-expression-builder';
import { Request } from '../request.model';
var ScanRequest = /** @class */ (function (_super) {
    tslib_1.__extends(ScanRequest, _super);
    function ScanRequest(dynamoRx, modelClazz, tableName) {
        return _super.call(this, dynamoRx, modelClazz, tableName) || this;
    }
    ScanRequest.prototype.whereAttribute = function (attributePath) {
        return RequestExpressionBuilder.addCondition('FilterExpression', attributePath, this, this.metaData);
    };
    ScanRequest.prototype.where = function () {
        var conditionDefFns = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            conditionDefFns[_i] = arguments[_i];
        }
        var condition = and.apply(void 0, tslib_1.__spread(conditionDefFns))(undefined, this.metaData);
        ParamUtil.addExpression('FilterExpression', condition, this.params);
        return this;
    };
    ScanRequest.prototype.execFullResponse = function () {
        var _this = this;
        delete this.params.Select;
        return this.dynamoRx.scan(this.params).pipe(map(function (queryResponse) {
            var response = tslib_1.__assign({}, queryResponse);
            response.Items = queryResponse.Items.map(function (item) { return Mapper.fromDb(item, _this.modelClazz); });
            return response;
        }));
    };
    ScanRequest.prototype.execNoMap = function () {
        return this.dynamoRx.scan(this.params);
    };
    ScanRequest.prototype.exec = function () {
        var _this = this;
        delete this.params.Select;
        return this.dynamoRx
            .scan(this.params)
            .pipe(map(function (response) { return response.Items.map(function (item) { return Mapper.fromDb(item, _this.modelClazz); }); }));
    };
    ScanRequest.prototype.execSingle = function () {
        var _this = this;
        delete this.params.Select;
        return this.dynamoRx
            .scan(this.params)
            .pipe(map(function (response) { return Mapper.fromDb(response.Items[0], _this.modelClazz); }));
    };
    ScanRequest.prototype.execCount = function () {
        var params = tslib_1.__assign({}, this.params);
        params.Select = 'COUNT';
        return this.dynamoRx.scan(params).pipe(map(function (response) { return response.Count; }));
    };
    /**
     * fetches all pages. may uses all provisionedOutput, therefore for client side use cases rather use pagedDatasource (exec)
     */
    ScanRequest.prototype.execFetchAll = function () {
        return fetchAll(this);
    };
    return ScanRequest;
}(Request));
export { ScanRequest };
//# sourceMappingURL=scan.request.js.map