package com.ghost.technic.server.card.effect.impl;

import com.ghost.technic.server.Player;
import com.ghost.technic.server.card.effect.StartOfOpponentTurnAbility;
import com.ghost.technic.server.card.misc.House;
import com.ghost.technic.server.card.playable.PlayableCard;
import com.ghost.technic.server.card.playable.usable.impl.CreatureCard;
import com.ghost.technic.server.game.GameActionService;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class SibylWaimareAbility implements StartOfOpponentTurnAbility {

    @Override
    public void onStartOfTurn(GameActionService gameActionService, Player activePlayer, PlayableCard source) {
        Player opponent = gameActionService.getGameState().getOwnerOf(source);
        var discardedCard = gameActionService.discordTopCardOfDeck(activePlayer);

        if (discardedCard instanceof PlayableCard playCard) {
            House house = playCard.getHouse();
            List<CreatureCard> creatures = activePlayer.getPlayArea().getBattleline().getCreatures();
            for (CreatureCard c : creatures) {
                if (c.getHouse() == house) {
                    c.setReady(false); // exhaust
                    log.info("Sibyl Waimare exhausts {}", c.getName());
                }
            }
        }
    }

    @Override
    public void register(GameActionService gameActionService, Player controller, PlayableCard source) {
        // no-op
    }
}
