package com.caliverse.admin.global.component.transaction;

import software.amazon.awssdk.enhanced.dynamodb.model.TransactWriteItemsEnhancedRequest;

public class DynamoDBTransactionContext {
    private static final ThreadLocal<TransactWriteItemsEnhancedRequest.Builder> currentTransaction = new ThreadLocal<>();

    public static void setTransactionBuilder(
            TransactWriteItemsEnhancedRequest.Builder builder) {
        currentTransaction.set(builder);
    }

    public static TransactWriteItemsEnhancedRequest.Builder getTransactionBuilder() {
        return currentTransaction.get();
    }

    public static void clear() {
        currentTransaction.remove();
    }

    public static boolean isInTransaction() {
        return currentTransaction.get() != null;
    }
}
