import * as tslib_1 from "tslib";
import { map, tap } from 'rxjs/operators';
import { hasSortKey } from '../../../decorator/metadata/metadata';
import { createLogger } from '../../../logger/logger';
import { toDbOne } from '../../../mapper';
import { WriteRequest } from '../write.request';
var DeleteRequest = /** @class */ (function (_super) {
    tslib_1.__extends(DeleteRequest, _super);
    function DeleteRequest(dynamoRx, modelClazz, tableName, partitionKey, sortKey) {
        var _this = _super.call(this, dynamoRx, modelClazz, tableName) || this;
        _this.logger = createLogger('dynamo.request.DeleteRequest', modelClazz);
        if (hasSortKey(_this.metadata) && (sortKey === null || sortKey === undefined)) {
            throw new Error("please provide the sort key for attribute " + _this.metadata.getSortKey());
        }
        var keyAttributeMap = {};
        // partition key
        var partitionKeyValue = toDbOne(partitionKey, _this.metadata.forProperty(_this.metadata.getPartitionKey()));
        if (partitionKeyValue === null) {
            throw new Error('please provide an acutal value for partition key, got null');
        }
        keyAttributeMap[_this.metadata.getPartitionKey()] = partitionKeyValue;
        // sort key
        if (hasSortKey(_this.metadata)) {
            var sortKeyValue = toDbOne(sortKey, _this.metadata.forProperty(_this.metadata.getSortKey()));
            if (sortKeyValue === null) {
                throw new Error('please provide an actual value for sort key, got null');
            }
            keyAttributeMap[_this.metadata.getSortKey()] = sortKeyValue;
        }
        _this.params.Key = keyAttributeMap;
        return _this;
    }
    DeleteRequest.prototype.execFullResponse = function () {
        var _this = this;
        this.logger.debug('request', this.params);
        return this.dynamoRx.deleteItem(this.params).pipe(tap(function (response) { return _this.logger.debug('response', response); }));
    };
    DeleteRequest.prototype.exec = function () {
        return this.execFullResponse().pipe(map(function (response) {
            return;
        }));
    };
    return DeleteRequest;
}(WriteRequest));
export { DeleteRequest };
//# sourceMappingURL=delete.request.js.map