package eu.jonahbauer.wizard.core;

import eu.jonahbauer.wizard.core.states.game.Finished;
import lombok.experimental.UtilityClass;
import org.mockito.Mockito;
import org.mockito.stubbing.Answer;
import org.mockito.stubbing.Stubber;

import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

@UtilityClass
public class GameTestUtils {
    public static Map<UUID, Integer> emptyToIntMap(List<UUID> players) {
        return players.stream().collect(Collectors.toUnmodifiableMap(player -> player, player -> 0));
    }

    public static Stubber doFinish() {
        return Mockito.doAnswer(finish());
    }

    public static <T> Answer<T> finish() {
        return invocation -> {
            Game game = (Game) invocation.getMock();
            game.execute(() -> Optional.of(new Finished()));
            return null;
        };
    }
}
