import * as tslib_1 from "tslib";
import { map, tap } from 'rxjs/operators';
import { createLogger } from '../../../logger/logger';
import { fromDb } from '../../../mapper';
import { Request } from '../request.model';
var ScanRequest = /** @class */ (function (_super) {
    tslib_1.__extends(ScanRequest, _super);
    function ScanRequest(dynamoRx, modelClazz) {
        var _this = _super.call(this, dynamoRx, modelClazz) || this;
        _this.mapFromDb = function (output) {
            var response = tslib_1.__assign({}, output);
            if (output.Items) {
                response.Items = output.Items.map(function (item) { return fromDb(item, _this.modelClazz); });
            }
            return response;
        };
        _this.logger = createLogger('dynamo.request.ScanRequest', modelClazz);
        return _this;
    }
    ScanRequest.prototype.execNoMap = function () {
        var _this = this;
        this.logger.debug('request (noMap)', this.params);
        return this.dynamoRx.scan(this.params)
            .pipe(tap(function (response) { return _this.logger.debug('response', response); }));
    };
    ScanRequest.prototype.execFullResponse = function () {
        var _this = this;
        this.logger.debug('request', this.params);
        return this.dynamoRx.scan(this.params).pipe(tap(function (response) { return _this.logger.debug('response', response); }), map(this.mapFromDb), tap(function (response) { return _this.logger.debug('mapped items', response.Items); }));
    };
    ScanRequest.prototype.exec = function () {
        var _this = this;
        this.logger.debug('request', this.params);
        return this.dynamoRx.scan(this.params).pipe(tap(function (response) { return _this.logger.debug('response', response); }), map(this.mapFromDb), map(function (r) { return r.Items; }), tap(function (items) { return _this.logger.debug('mapped items', items); }));
    };
    ScanRequest.prototype.execSingle = function () {
        var _this = this;
        var params = tslib_1.__assign({}, this.params, { Limit: 1 });
        this.logger.debug('single request', params);
        return this.dynamoRx.scan(this.params).pipe(tap(function (response) { return _this.logger.debug('response', response); }), map(this.mapFromDb), map(function (r) { return r.Items && r.Items.length ? r.Items[0] : null; }), tap(function (item) { return _this.logger.debug('mapped item', item); }));
    };
    ScanRequest.prototype.execCount = function () {
        var _this = this;
        var params = tslib_1.__assign({}, this.params, { Select: 'COUNT' });
        this.logger.debug('count request', params);
        return this.dynamoRx.scan(params).pipe(tap(function (response) { return _this.logger.debug('response', response); }), map(function (response) { return response.Count || 0; }), tap(function (count) { return _this.logger.debug('count', count); }));
    };
    return ScanRequest;
}(Request));
export { ScanRequest };
//# sourceMappingURL=scan.request.js.map