package de.accso.flexinale.common.shared_kernel;

import org.apache.commons.collections4.multimap.AbstractSetValuedMap;

import java.util.*;

public final class SelectionMultiMap<K, V> extends AbstractSetValuedMap<K, V> {
    private final Selection.SelectionAlgorithm selectionAlgorithm;

    public SelectionMultiMap(Selection.SelectionAlgorithm selectionAlgorithm) {
        super(new HashMap<K, Selection<V>>());
        this.selectionAlgorithm = selectionAlgorithm;
    }

    @Override
    protected Set<V> createCollection() {
        return switch (selectionAlgorithm) {
            case RANDOM ->  new Selection.RandomSelector<>();
            case CONSTANT_FIRST -> new Selection.ConstantFirstSelector<>();
            case CONSTANT_LAST -> new Selection.ConstantLastSelector<>();
            case ROUND_ROBIN -> new Selection.RoundRobinSelector<>();
            case ALL -> new Selection.AllSelector<>();
        };
    }

    @Override
    public Set<V> get(final K key) {
        return getMap().get(key);
    }
}
