package it.polimi.ingsw.gc14.Model.Cards.Building.Effects;

import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.Cards.BuildingCard;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Characters.Artist;
import it.polimi.ingsw.gc14.Model.Player;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.Character;
import it.polimi.ingsw.gc14.Model.Cards.TribeCards.CharacterType;

import java.util.ArrayList;
import java.util.HashMap;

public class Building0 extends BuildingCard {

    boolean purchased ;
    private int numSet;



    public Building0(int era,int price,int prestigeValue) {
        super(era,price,prestigeValue);
        effectType=EffectType.CARD_SET;
        effectId=0;
        purchased = false;
        numSet = 0;
    }

    @Override
    public boolean buy(Player player)
    {
        if(!super.buy(player))
            return false;
        initialize(player);
        return true;
    }

    public void initialize(Player player)
    {
        if(purchased)
        {
            return;
        }
        numSet=player.getNType(CharacterType.INVENTOR);
        for(CharacterType type : CharacterType.values())
        {
            if(player.getNType(type)<=numSet)
                numSet=player.getNType(type);
        }
        purchased = true;

    }
    @Override
    public BuildingCard clone() {
        return new Building0(getEra(),getPrice(),getPrestigeValue());
    }
    @Override
    public void applyEffect(Player player) throws IllegalArgumentException {
        if(!player.buildingCards.contains(this))
            throw new IllegalArgumentException();
        int min_temp=player.getNType(CharacterType.INVENTOR);
        for(CharacterType type : CharacterType.values())
        {
            if(player.getNType(type)<=min_temp)
                min_temp=player.getNType(type);
        }
        if(min_temp<=numSet)
        {
            return;
        }
        player.addFood(5*(min_temp-numSet));
        numSet=min_temp;
    };

}
