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';
export class ScanRequest extends Request {
    constructor(dynamoRx, modelClazz, tableName) {
        super(dynamoRx, modelClazz, tableName);
    }
    whereAttribute(attributePath) {
        return RequestExpressionBuilder.addCondition('FilterExpression', attributePath, this, this.metaData);
    }
    where(...conditionDefFns) {
        const condition = and(...conditionDefFns)(undefined, this.metaData);
        ParamUtil.addExpression('FilterExpression', condition, this.params);
        return this;
    }
    execFullResponse() {
        delete this.params.Select;
        return this.dynamoRx.scan(this.params).pipe(map(queryResponse => {
            const response = Object.assign({}, queryResponse);
            response.Items = queryResponse.Items.map(item => 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(map(response => response.Items.map(item => Mapper.fromDb(item, this.modelClazz))));
    }
    execSingle() {
        delete this.params.Select;
        return this.dynamoRx
            .scan(this.params)
            .pipe(map(response => Mapper.fromDb(response.Items[0], this.modelClazz)));
    }
    execCount() {
        const params = Object.assign({}, this.params);
        params.Select = 'COUNT';
        return this.dynamoRx.scan(params).pipe(map(response => response.Count));
    }
    /**
     * fetches all pages. may uses all provisionedOutput, therefore for client side use cases rather use pagedDatasource (exec)
     */
    execFetchAll() {
        return fetchAll(this);
    }
}
//# sourceMappingURL=scan.request.js.map