"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operators_1 = require("rxjs/operators");
const helper_1 = require("../../../helper");
const mapper_1 = require("../../../mapper/mapper");
const and_function_1 = require("../../expression/logical-operator/and.function");
const param_util_1 = require("../../expression/param-util");
const request_expression_builder_1 = require("../../expression/request-expression-builder");
const request_model_1 = require("../request.model");
class ScanRequest extends request_model_1.Request {
    constructor(dynamoRx, modelClazz, tableName) {
        super(dynamoRx, modelClazz, tableName);
    }
    whereAttribute(attributePath) {
        return request_expression_builder_1.RequestExpressionBuilder.addCondition('FilterExpression', attributePath, this, this.metaData);
    }
    where(...conditionDefFns) {
        const condition = and_function_1.and(...conditionDefFns)(undefined, this.metaData);
        param_util_1.ParamUtil.addExpression('FilterExpression', condition, this.params);
        return this;
    }
    execFullResponse() {
        delete this.params.Select;
        return this.dynamoRx.scan(this.params).pipe(operators_1.map(queryResponse => {
            const response = Object.assign({}, queryResponse);
            response.Items = queryResponse.Items.map(item => mapper_1.Mapper.fromDb(item, this.modelClazz));
            return response;
        }));
    }
    execNoMap() {
        return this.dynamoRx.scan(this.params);
    }
    exec() {
        delete this.params.Select;
        return this.dynamoRx
            .scan(this.params)
            .pipe(operators_1.map(response => response.Items.map(item => mapper_1.Mapper.fromDb(item, this.modelClazz))));
    }
    execSingle() {
        delete this.params.Select;
        return this.dynamoRx
            .scan(this.params)
            .pipe(operators_1.map(response => mapper_1.Mapper.fromDb(response.Items[0], this.modelClazz)));
    }
    execCount() {
        const params = Object.assign({}, this.params);
        params.Select = 'COUNT';
        return this.dynamoRx.scan(params).pipe(operators_1.map(response => response.Count));
    }
    /**
     * fetches all pages. may uses all provisionedOutput, therefore for client side use cases rather use pagedDatasource (exec)
     */
    execFetchAll() {
        return helper_1.fetchAll(this);
    }
}
exports.ScanRequest = ScanRequest;
//# sourceMappingURL=scan.request.js.map