import { map, tap } from 'rxjs/operators';
import { createLogger } from '../../../logger/logger';
import { fromDb } from '../../../mapper';
import { Request } from '../request.model';
export class ScanRequest extends Request {
    constructor(dynamoRx, modelClazz) {
        super(dynamoRx, modelClazz);
        this.mapFromDb = (output) => {
            const response = Object.assign({}, output);
            if (output.Items) {
                response.Items = output.Items.map(item => fromDb(item, this.modelClazz));
            }
            return response;
        };
        this.logger = createLogger('dynamo.request.ScanRequest', modelClazz);
    }
    execNoMap() {
        this.logger.debug('request (noMap)', this.params);
        return this.dynamoRx.scan(this.params)
            .pipe(tap(response => this.logger.debug('response', response)));
    }
    execFullResponse() {
        this.logger.debug('request', this.params);
        return this.dynamoRx.scan(this.params).pipe(tap(response => this.logger.debug('response', response)), map(this.mapFromDb), tap(response => this.logger.debug('mapped items', response.Items)));
    }
    exec() {
        this.logger.debug('request', this.params);
        return this.dynamoRx.scan(this.params).pipe(tap(response => this.logger.debug('response', response)), map(this.mapFromDb), map(r => r.Items), tap(items => this.logger.debug('mapped items', items)));
    }
    execSingle() {
        const params = Object.assign({}, this.params, { Limit: 1 });
        this.logger.debug('single request', params);
        return this.dynamoRx.scan(this.params).pipe(tap(response => this.logger.debug('response', response)), map(this.mapFromDb), map(r => r.Items && r.Items.length ? r.Items[0] : null), tap(item => this.logger.debug('mapped item', item)));
    }
    execCount() {
        const params = Object.assign({}, this.params, { Select: 'COUNT' });
        this.logger.debug('count request', params);
        return this.dynamoRx.scan(params).pipe(tap(response => this.logger.debug('response', response)), map(response => response.Count || 0), tap(count => this.logger.debug('count', count)));
    }
}
//# sourceMappingURL=scan.request.js.map