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

import it.polimi.ingsw.gc14.Model.Cards.Building.BuildingEffect;
import it.polimi.ingsw.gc14.Model.Cards.Building.EffectType;
import it.polimi.ingsw.gc14.Model.PlayableCard;
import it.polimi.ingsw.gc14.Model.Player;

import java.util.ArrayList;

public class BuildingCard extends PlayableCard implements Cloneable , BuildingEffect {
    private int price;
    public int getPrice() {
        return price;
    }
    private boolean bought;
    protected EffectType effectType;
    protected int effectId;
    private int prestigeValue;
    public int  getPrestigeValue() {
        return prestigeValue;
    }
    public int getEffectId() {
        return effectId;
    }
    public EffectType getEffectType() {
        return effectType;
    }

    public BuildingCard(int era,int price,int prestigeValue) throws IllegalArgumentException{
        super(era);
        if (price > 0) {
            this.price = price;
        } else {
            throw new IllegalArgumentException();
        }
        if (prestigeValue >= 0) {
            this.prestigeValue = prestigeValue;
        } else {
            throw new IllegalArgumentException();
        }

        bought = false;
    }
    public BuildingCard(int effectId ,int era,int price,int prestigeValue) throws IllegalArgumentException{
        this.effectId = effectId;
        switch (effectId){
            case 2:
                this.effectType=EffectType.ON_EVENT;
                break;
            case 3:
                this.effectType=EffectType.ON_END_TURN;
                break;
            case 5:
                this.effectType=EffectType.ON_EVENT;
                break;
            case 6:
                this.effectType=EffectType.ON_EVENT;
                break;
            case 7:
                this.effectType=EffectType.ON_EVENT;
                break;
            case 9:
                this.effectType=EffectType.ON_EVENT;
                break;
            case 12:
                    this.effectType=EffectType.ON_ROUND_END;
                break;
            default:
                throw new IllegalArgumentException();

        }
        this(era,price,prestigeValue);
    }


    @Override
    public BuildingCard clone()
    {
        return new BuildingCard(effectId,getEra(),getPrice(),getPrestigeValue());
    }
    public boolean buy(Player player) {
        if( bought || !player.removeFood(getPrice()))
            return false;
        player.buildingCards.add(this);
        bought=true;
        return true;
    }
    public void applyEffect(Player player){};

    @Override
    public String toString() {
        return "Era:"+String.valueOf(getEra())+"\nPrice:"+String.valueOf(getPrice())+"\nPrestige:"+String.valueOf(getPrestigeValue()+"\n");
    }
}
