import { tap } from 'rxjs/operators';
import { createLogger } from '../logger/logger';
import { DynamoRx } from './dynamo-rx';
import { getTableName } from './get-table-name.function';
import { BatchGetSingleTableRequest, DeleteRequest, GetRequest, PutRequest, QueryRequest, ScanRequest, TransactGetSingleTableRequest, UpdateRequest, } from './request';
import { BatchWriteSingleTableRequest } from './request/batchwritesingletable/batch-write-single-table.request';
export class DynamoStore {
    constructor(modelClazz) {
        this.modelClazz = modelClazz;
        this.logger = createLogger('dynamo.DynamoStore', modelClazz);
        this.dynamoRx = new DynamoRx();
        this.tableName = getTableName(modelClazz);
        this.logger.debug('instance created');
    }
    get dynamoDB() {
        return this.dynamoRx.dynamoDB;
    }
    put(item) {
        return new PutRequest(this.dynamoRx, this.modelClazz, item);
    }
    get(partitionKey, sortKey) {
        return new GetRequest(this.dynamoRx, this.modelClazz, partitionKey, sortKey);
    }
    update(partitionKey, sortKey) {
        return new UpdateRequest(this.dynamoRx, this.modelClazz, partitionKey, sortKey);
    }
    delete(partitionKey, sortKey) {
        return new DeleteRequest(this.dynamoRx, this.modelClazz, partitionKey, sortKey);
    }
    scan() {
        return new ScanRequest(this.dynamoRx, this.modelClazz);
    }
    query() {
        return new QueryRequest(this.dynamoRx, this.modelClazz);
    }
    /**
     * This is a special implementation of BatchGetItem request, because it only supports one table,
     * if you wish to retrieve items from multiple tables
     * create an instance of BatchGetItemInput and use store.makeRequest with it.
     */
    batchGet(keys) {
        return new BatchGetSingleTableRequest(this.dynamoRx, this.modelClazz, keys);
    }
    /**
     * This is a special implementation of batchWriteItem request, because it only supports one table,
     * if you wish to write items to multiple tables
     * create an instance of BatchWriteItemInput and use store.makeRequest with it.
     */
    batchWrite() {
        return new BatchWriteSingleTableRequest(this.dynamoRx, this.modelClazz);
    }
    transactGet(keys) {
        return new TransactGetSingleTableRequest(this.dynamoRx, this.modelClazz, keys);
    }
    makeRequest(operation, params) {
        this.logger.debug('request', params);
        return this.dynamoRx.makeRequest(operation, params).pipe(tap(response => this.logger.debug('response', response)));
    }
}
//# sourceMappingURL=dynamo-store.js.map