"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const operators_1 = require("rxjs/operators");
const metadata_1 = require("../../../decorator/metadata/metadata");
const logger_1 = require("../../../logger/logger");
const mapper_1 = require("../../../mapper");
const write_request_1 = require("../write.request");
class DeleteRequest extends write_request_1.WriteRequest {
    constructor(dynamoRx, modelClazz, tableName, partitionKey, sortKey) {
        super(dynamoRx, modelClazz, tableName);
        this.logger = logger_1.createLogger('dynamo.request.DeleteRequest', modelClazz);
        if (metadata_1.hasSortKey(this.metadata) && (sortKey === null || sortKey === undefined)) {
            throw new Error(`please provide the sort key for attribute ${this.metadata.getSortKey()}`);
        }
        const keyAttributeMap = {};
        // partition key
        const partitionKeyValue = mapper_1.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 (metadata_1.hasSortKey(this.metadata)) {
            const sortKeyValue = mapper_1.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;
    }
    execFullResponse() {
        this.logger.debug('request', this.params);
        return this.dynamoRx.deleteItem(this.params).pipe(operators_1.tap(response => this.logger.debug('response', response)));
    }
    exec() {
        return this.execFullResponse().pipe(operators_1.map(response => {
            return;
        }));
    }
}
exports.DeleteRequest = DeleteRequest;
//# sourceMappingURL=delete.request.js.map