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';
export class DeleteRequest extends WriteRequest {
    constructor(dynamoRx, modelClazz, tableName, partitionKey, sortKey) {
        super(dynamoRx, modelClazz, tableName);
        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()}`);
        }
        const keyAttributeMap = {};
        // partition key
        const 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)) {
            const 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;
    }
    execFullResponse() {
        this.logger.debug('request', this.params);
        return this.dynamoRx.deleteItem(this.params).pipe(tap(response => this.logger.debug('response', response)));
    }
    exec() {
        return this.execFullResponse().pipe(map(response => {
            return;
        }));
    }
}
//# sourceMappingURL=delete.request.js.map