package com.gempukku.lotro.cards.set2.dwarven;

import com.gempukku.lotro.cards.AbstractAttachableFPPossession;
import com.gempukku.lotro.cards.effects.PreventEffect;
import com.gempukku.lotro.common.Culture;
import com.gempukku.lotro.common.Keyword;
import com.gempukku.lotro.common.Race;
import com.gempukku.lotro.filters.Filter;
import com.gempukku.lotro.filters.Filters;
import com.gempukku.lotro.game.PhysicalCard;
import com.gempukku.lotro.game.state.LotroGame;
import com.gempukku.lotro.logic.actions.ActivateCardAction;
import com.gempukku.lotro.logic.effects.DiscardCardsFromPlayEffect;
import com.gempukku.lotro.logic.effects.WoundCharactersEffect;
import com.gempukku.lotro.logic.timing.Action;
import com.gempukku.lotro.logic.timing.Effect;
import com.gempukku.lotro.logic.timing.EffectResult;

import java.util.Collections;
import java.util.List;

/**
 * Set: Mines of Moria
 * Side: Free
 * Culture: Dwarven
 * Twilight Cost: 1
 * Type: Possession • Bracers
 * Strength: +1
 * Game Text: Bearer must be a Dwarf. Response: If bearer is about to take a wound, discard this possession to prevent
 * that wound.
 */
public class Card2_003 extends AbstractAttachableFPPossession {
    public Card2_003() {
        super(1, 1, 0, Culture.DWARVEN, Keyword.BRACERS, "Dwarven Bracers");
    }

    @Override
    protected Filter getValidTargetFilter(String playerId, LotroGame game, PhysicalCard self) {
        return Filters.race(Race.DWARF);
    }

    @Override
    public List<? extends Action> getOptionalBeforeActions(String playerId, LotroGame game, Effect effect, PhysicalCard self) {
        if (effect.getType() == EffectResult.Type.WOUND
                && ((WoundCharactersEffect) effect).getAffectedCardsMinusPrevented(game).contains(self.getAttachedTo())) {
            ActivateCardAction action = new ActivateCardAction(self, Keyword.RESPONSE);
            action.appendCost(
                    new DiscardCardsFromPlayEffect(self));
            action.appendEffect(
                    new PreventEffect((WoundCharactersEffect) effect, self.getAttachedTo()));
            return Collections.singletonList(action);
        }
        return null;
    }
}
