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

import com.ghost.technic.server.Player;
import com.ghost.technic.server.card.effect.CardAbility;
import com.ghost.technic.server.card.misc.House;
import com.ghost.technic.server.card.playable.PlayableCard;
import com.ghost.technic.server.game.GameActionService;
import com.ghost.technic.server.game.event.EventType;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class ScreeyanAbility implements CardAbility {

    @Override
    public void register(GameActionService service, Player controller, PlayableCard source) {
        service.getEventBus().subscribe(EventType.TURN_ENDS, event -> {
            Player current = event.get("player");
            Player opponent = service.getGameState().getOpponentOf(current);

            PlayableCard discardedCard = service.discordTopCardOfDeck(opponent);
            if (discardedCard != null) {
                House discardedHouse = discardedCard.getHouse();
                log.info("[Screeyan] {} discarded. {} may not choose {} next turn.",
                        discardedCard.getName(), opponent.getName(), discardedHouse);

                service.getGameState().restrictHouseNextTurn(opponent, discardedHouse);
            }
        });
    }
}
