import * as tslib_1 from "tslib";
import { map } from 'rxjs/operators';
import { Mapper } from '../../../mapper/mapper';
import { and } from '../../expression/logical-operator/and.function';
import { ParamUtil } from '../../expression/param-util';
import { RequestExpressionBuilder } from '../../expression/request-expression-builder';
import { BaseRequest } from '../base.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;
        var hasSortKey = _this.metaData.getSortKey() !== null;
        if (hasSortKey && (sortKey === null || sortKey === undefined)) {
            throw new Error("please provide the sort key for attribute " + _this.metaData.getSortKey());
        }
        var keyAttributeMap = {};
        // partition key
        var partitionKeyValue = Mapper.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) {
            var sortKeyValue = Mapper.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.whereAttribute = function (attributePath) {
        return RequestExpressionBuilder.addCondition('ConditionExpression', attributePath, this, this.metaData);
    };
    DeleteRequest.prototype.where = function () {
        var conditionDefFns = [];
        for (var _i = 0; _i < arguments.length; _i++) {
            conditionDefFns[_i] = arguments[_i];
        }
        var condition = and.apply(void 0, tslib_1.__spread(conditionDefFns))(undefined, this.metaData);
        ParamUtil.addExpression('ConditionExpression', condition, this.params);
        return this;
    };
    DeleteRequest.prototype.returnConsumedCapacity = function (level) {
        this.params.ReturnConsumedCapacity = level;
        return this;
    };
    DeleteRequest.prototype.returnItemCollectionMetrics = function (returnItemCollectionMetrics) {
        this.params.ReturnItemCollectionMetrics = returnItemCollectionMetrics;
        return this;
    };
    /*
       * The ReturnValues parameter is used by several DynamoDB operations; however,
       * DeleteItem does not recognize any values other than NONE or ALL_OLD.
       */
    DeleteRequest.prototype.returnValues = function (returnValues) {
        this.params.ReturnValues = returnValues;
        return this;
    };
    DeleteRequest.prototype.execFullResponse = function () {
        return this.dynamoRx.deleteItem(this.params);
    };
    DeleteRequest.prototype.exec = function () {
        return this.dynamoRx.deleteItem(this.params).pipe(map(function (response) {
            return;
        }));
    };
    return DeleteRequest;
}(BaseRequest));
export { DeleteRequest };
//# sourceMappingURL=delete.request.js.map