import { tap } from 'rxjs/operators';
import { createLogger } from '../../../logger/logger';
import { toDb } from '../../../mapper';
import { createIfNotExistsCondition } from '../../expression/create-if-not-exists-condition.function';
import { WriteRequest } from '../write.request';
export class PutRequest extends WriteRequest {
    constructor(dynamoRx, modelClazz, item) {
        super(dynamoRx, modelClazz);
        this.logger = createLogger('dynamo.request.PutRequest', modelClazz);
        this.params.Item = toDb(item, this.modelClazz);
    }
    /**
     * Adds a condition expression to the request, which makes sure the item will only be saved if the id does not exist
     * @returns {PutRequest<T>}
     */
    ifNotExists(predicate = true) {
        if (predicate) {
            this.onlyIf(...createIfNotExistsCondition(this.metadata));
        }
        return this;
    }
    execFullResponse() {
        this.logger.debug('request', this.params);
        return this.dynamoRx.putItem(this.params).pipe(tap(response => this.logger.debug('response', response)));
    }
}
//# sourceMappingURL=put.request.js.map