package eu.jonahbauer.wizard.core.model.card;

import eu.jonahbauer.wizard.common.model.Card;
import eu.jonahbauer.wizard.core.util.Pair;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.jetbrains.annotations.Contract;

import java.util.List;
import java.util.UUID;

@Getter
@RequiredArgsConstructor
public abstract class GameCard {
    private final Card card;

    public abstract Card.Suit getTrumpSuit();
    public abstract Card.Suit getTrickSuit();

    /**
     * Standard implementation of playing a card.
     * <br>
     * Removes the card from the hand checking that the hand contains it and then adds a new entry to the stack.
     * @param player the player playing this card
     * @param hand the player's hand cards
     * @param stack the stack
     */
    @Contract(mutates = "param2, param3")
    public void play(UUID player, List<Card> hand, List<Pair<UUID, Card>> stack) {
        checkHand(hand);
        hand.remove(getCard());
        stack.add(Pair.of(player, getCard()));
    }

    public boolean isPlayable(List<Card> hand, List<Pair<UUID, Card>> stack) {
        return hand.contains(getCard());
    }

    protected void checkHand(List<Card> hand) {
        if (!hand.contains(getCard())) {
            throw new IllegalArgumentException("You do not have this card on your hand.");
        }
    }
}
