package Server;

import Server.Cards.CharacterCard;

import java.util.Objects;

public class Player {

    //Attributes
    private String nickname;
    private TotemColor totemColor;
    private int foodTokens;
    private int prestigePoints;
    private Tribe playerTribe;


    //Constructor
    public Player(String nickname, TotemColor totemColor) {
        this.nickname = nickname;
        this.totemColor = totemColor;
        this.foodTokens = 0;
        this.prestigePoints = 0;
        this.playerTribe = new Tribe();
    }

    //Methods
    public void addFood(int food){
        this.foodTokens += food;
    }

    public boolean removeFood(int food){
        if (this.foodTokens >= food) {
            this.foodTokens -= food;
            return true; // Pagamento andato a buon fine
        }
        return false; // Il giocatore non ha abbastanza cibo, transazione negata, la quantità di cibo rimane quella di prima.
    }

    public void addPrestigePoints(int prestige){
        this.prestigePoints += prestige;
    }

    public int removePrestigePoints(int prestige){
        this.prestigePoints -= prestige;
        return prestigePoints;
    }

    public void addCharacterToTribe(CharacterCard card) {
        int foodGained = this.playerTribe.addCharacter(card);
        this.addFood(foodGained);
    }

    //Getters
    public String getNickname() {
        return nickname;
    }

    public int getFoodTokens() {
        return foodTokens;
    }

    public int getPrestigePoints() {
        return prestigePoints;
    }

    public TotemColor getTotemColor() {
        return totemColor;
    }

    public Tribe getPlayerTribe() {
        return playerTribe;
    }

    // two Player objects to be considered equal only by nickname
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Player player = (Player) o;
        return Objects.equals(nickname, player.nickname);
    }

    @Override
    public int hashCode() {
        return Objects.hash(nickname);
    }

    @Override
    public String toString() {
        return "Player(" +
                "name='" + nickname + '\'' +
                ", food=" + foodTokens +
                ", pp=" + prestigePoints +
                ')';
    }
}
