import * as tslib_1 from "tslib";
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';
var PutRequest = /** @class */ (function (_super) {
    tslib_1.__extends(PutRequest, _super);
    function PutRequest(dynamoRx, modelClazz, item) {
        var _this = _super.call(this, dynamoRx, modelClazz) || this;
        _this.logger = createLogger('dynamo.request.PutRequest', modelClazz);
        _this.params.Item = toDb(item, _this.modelClazz);
        return _this;
    }
    /**
     * 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>}
     */
    PutRequest.prototype.ifNotExists = function (predicate) {
        if (predicate === void 0) { predicate = true; }
        if (predicate) {
            this.onlyIf.apply(this, tslib_1.__spread(createIfNotExistsCondition(this.metadata)));
        }
        return this;
    };
    PutRequest.prototype.execFullResponse = function () {
        var _this = this;
        this.logger.debug('request', this.params);
        return this.dynamoRx.putItem(this.params).pipe(tap(function (response) { return _this.logger.debug('response', response); }));
    };
    return PutRequest;
}(WriteRequest));
export { PutRequest };
//# sourceMappingURL=put.request.js.map