package io.delphiplatform.api.integration.context.bigtable;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

@Component
public class BigtableTestDataExecutorMapper {

    private final Map<String, BigtableTestDataExecutor> executors;

    @Autowired
    public BigtableTestDataExecutorMapper(List<BigtableTestDataExecutor> executors) {
        this.executors = executors.stream()
            .collect(Collectors.toMap(BigtableTestDataExecutor::getTableName, Function.identity()));
    }

    public BigtableTestDataExecutor executorForTable(String tableName) {
        if (executors.containsKey(tableName)) {
            return executors.get(tableName);
        }

        throw new RuntimeException("Unsupportable BT table: " + tableName);
    }
}
