package com.trunksbomb.minetriad.game;

import java.util.List;

import net.minecraft.resources.ResourceLocation;

public record MoveResult(
        boolean valid,
        String errorMessage,
        List<List<BoardCell>> captureWaves,
        List<BoardCell> capturedCells,
        List<String> battleLog,
        String playedCardName,
        ResourceLocation playedCardId,
        BoardCell playedCell) {
    public static MoveResult success(
            List<List<BoardCell>> captureWaves,
            List<String> battleLog,
            String playedCardName,
            ResourceLocation playedCardId,
            BoardCell playedCell) {
        List<List<BoardCell>> immutableWaves = captureWaves.stream()
                .map(List::copyOf)
                .toList();
        List<BoardCell> flattenedCaptures = immutableWaves.stream()
                .flatMap(List::stream)
                .distinct()
                .toList();
        return new MoveResult(true, "", immutableWaves, flattenedCaptures, List.copyOf(battleLog), playedCardName, playedCardId, playedCell);
    }

    public static MoveResult failure(String errorMessage) {
        return new MoveResult(false, errorMessage, List.of(), List.of(), List.of(), "", null, null);
    }
}
