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';
export class DeleteRequest extends BaseRequest {
    constructor(dynamoRx, modelClazz, tableName, partitionKey, sortKey) {
        super(dynamoRx, modelClazz, tableName);
        const hasSortKey = this.metaData.getSortKey() !== null;
        if (hasSortKey && (sortKey === null || sortKey === undefined)) {
            throw new Error(`please provide the sort key for attribute ${this.metaData.getSortKey()}`);
        }
        const keyAttributeMap = {};
        // partition key
        const 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) {
            const 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;
    }
    whereAttribute(attributePath) {
        return RequestExpressionBuilder.addCondition('ConditionExpression', attributePath, this, this.metaData);
    }
    where(...conditionDefFns) {
        const condition = and(...conditionDefFns)(undefined, this.metaData);
        ParamUtil.addExpression('ConditionExpression', condition, this.params);
        return this;
    }
    returnConsumedCapacity(level) {
        this.params.ReturnConsumedCapacity = level;
        return this;
    }
    returnItemCollectionMetrics(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.
       */
    returnValues(returnValues) {
        this.params.ReturnValues = returnValues;
        return this;
    }
    execFullResponse() {
        return this.dynamoRx.deleteItem(this.params);
    }
    exec() {
        return this.dynamoRx.deleteItem(this.params).pipe(map(response => {
            return;
        }));
    }
}
//# sourceMappingURL=delete.request.js.map