package it.polimi.ingsw.gc14.Model;

import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.*;

import java.util.ArrayList;
import java.util.Arrays;

import static java.lang.Math.abs;

public class Player {
    // Getters
    private String UserName;
    public String getUserName() {
        return UserName;
    }

    public int getTotCharacters() {
        return Arrays.stream(CharacterType.values())
                .mapToInt(this::getNType)
                .sum();
    }
    public int getNType(CharacterType type) {
        return switch (type) {
            case ARTIST -> artists.size();
            case INVENTOR -> inventors.size();
            case HUNTER -> hunters.size();
            case BUILDER -> builders.size();
            case SHAMAN -> shamans.size();
            case GATHERER -> gatherers.size();
        };
    }

    public ArrayList <BuildingCard> buildingCards;

    public ArrayList <Artist> artists;
    public ArrayList <Builder> builders;
    public ArrayList <Inventor> inventors;
    public ArrayList <Gatherer>  gatherers;
    public ArrayList <Shaman> shamans;
    public ArrayList <Hunter> hunters;

    private int FoodValue;
    public int getFoodValue() {
        return FoodValue;
    }

    private int PrestigeValue;
    public int getPrestigeValue() {
        return PrestigeValue;
    }

    /* TODO
    * private Game game;
    * public Game getGame(){
    *   return Game;
    * }
    */
    // End getters

    // Setters
    public void addFood(int Value){
        this.FoodValue += Value;
    }

    public Boolean removeFood(int Value){
        if(Value > this.FoodValue){
            return false;
        }
        this.FoodValue -= Value;
        return true;
    }

    public void addPrestige(int Value){

        this.PrestigeValue += Value;
    }

    public void removePrestige(int Value){

        this.PrestigeValue -= Value;
    }
    // End setters

    // Constructors
    public Player(String UserName) throws  IllegalArgumentException {
        if(UserName.isEmpty() || UserName.length() > 32) {
            throw new IllegalArgumentException();
        }
        this.UserName = UserName;

        this.inventors = new ArrayList <>();
        this.builders = new ArrayList <>();
        this.gatherers = new ArrayList <>();
        this.shamans = new ArrayList <>();
        this.hunters = new ArrayList <>();
        this.artists = new ArrayList<>();

        this.buildingCards = new ArrayList<>();
        this.FoodValue = 0;
        this.PrestigeValue = 0;
    }
    // End constructors

    // Functions
    // TODO
    public void Play(Slot slot){

    }

    // TODO
    public void SlotChoice(){

    }
    // End functions
}
