"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operators_1 = require("rxjs/operators");
const logger_1 = require("../../../logger/logger");
const mapper_1 = require("../../../mapper");
const create_if_not_exists_condition_function_1 = require("../../expression/create-if-not-exists-condition.function");
const write_request_1 = require("../write.request");
class PutRequest extends write_request_1.WriteRequest {
    constructor(dynamoRx, modelClazz, item) {
        super(dynamoRx, modelClazz);
        this.logger = logger_1.createLogger('dynamo.request.PutRequest', modelClazz);
        this.params.Item = mapper_1.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(...create_if_not_exists_condition_function_1.createIfNotExistsCondition(this.metadata));
        }
        return this;
    }
    execFullResponse() {
        this.logger.debug('request', this.params);
        return this.dynamoRx.putItem(this.params).pipe(operators_1.tap(response => this.logger.debug('response', response)));
    }
}
exports.PutRequest = PutRequest;
//# sourceMappingURL=put.request.js.map