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.card.playable.usable.impl.CreatureCard;
import com.ghost.technic.server.game.GameActionService;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class PersistenceHuntingAbility implements CardAbility {

    @Override
    public void register(GameActionService gameActionService, Player controller, PlayableCard source) {
        House chosen = controller.chooseHouse(House.getAllHouses());
        log.info("{} chooses {} for Persistence Hunting", controller.getName(), chosen);

        Player opponent = gameActionService.getGameState().getOpponentOf(controller);
        List<CreatureCard> targets = opponent.getPlayArea().getBattleline().getCreatures().stream()
                .filter(creature -> creature.getHouse() == chosen)
                .toList();

        for (CreatureCard target : targets) {
            target.setReady(false); // Exhaust
            log.info("{} is exhausted by Persistence Hunting", target.getName());
        }
    }
}
