//
// Created by sebastian on 05.08.26.
//

#ifndef COLORRACE_LUDORULES_H
#define COLORRACE_LUDORULES_H
#include <optional>

#include "../LudoTypes.h"
#include "ludo/LudoGameState.h"


// LudoRules.h
namespace ludo {
    struct Destination {
        PieceState state;
        int position;
    };
    class LudoRules {
    public:
        // Alles hier: reine Funktionen, keine Member, kein Zustand.
        // Nimmt GameState als Parameter, verändert nichts, wirft keine Events.

        static int getEntryOffset(PlayerColor color);

        static std::optional<Destination> computeDestination(const LudoGameState& state,
                                                             const Piece& piece, int diceValue);

        static bool isBlockedByOwnPiece(const LudoGameState& state, PlayerColor owner, PieceState pieceState, int position);

        static std::optional<int> wouldCapture(const LudoGameState& state, int pieceIndex, int diceValue);


        static std::vector<int> getMoveablePieceIndices(const LudoGameState& state, PlayerColor color, int diceValue);

        static std::optional<int> findLowestHomeSlotPiece(const LudoGameState& state, PlayerColor color);

        struct MoveResult {
            int fromPosition = 0;
            int toPosition = 0;
            bool captured = false;
            int capturedPieceIndex = -1;
            PieceState targetState = PieceState::OnTrack;
            PieceState startState = PieceState::OnTrack;
        };
        static MoveResult computeMoveResult(const LudoGameState& state, int pieceIndex, int diceValue);


    };



} // namespace ludo


#endif //COLORRACE_LUDORULES_H
