package com.ghost.technic.server.card.playable;

import com.ghost.technic.server.Player;
import com.ghost.technic.server.card.Card;
import com.ghost.technic.server.card.effect.CardAbility;
import com.ghost.technic.server.card.misc.BonusIcons;
import com.ghost.technic.server.card.misc.House;
import com.ghost.technic.server.game.event.*;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.experimental.SuperBuilder;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Data
@Slf4j
@SuperBuilder
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
@EqualsAndHashCode(callSuper = true, onlyExplicitlyIncluded = true)
public abstract class PlayableCard extends Card {
    @ToString.Include
    private House house;
    private BonusIcons bonusIcons;
    @Builder.Default
    private List<CardAbility> abilities = new ArrayList<>();

    public void play(Player player, EventBus eventBus) {
        publishUsedEvent(player, UsageType.PLAY, eventBus);
    }

    public void publishUsedEvent(Player player, UsageType usageType, EventBus eventBus) {
        UsedEventData usedData = new UsedEventData(this, usageType);
        Map<String, Object> payload = Map.of("usedEventData", usedData);
        GameEvent usedEvent = new GameEvent(EventType.USED, payload);
        eventBus.publish(usedEvent);
        log.info("{} {} {}", player.getName(), usageType, getName());
    }

    public void addAbility(CardAbility ability) {
        abilities.add(ability);
    }
}
