package pp.monopoly.model.fields;

import pp.monopoly.game.server.Player;

public class BuildingProperty extends PropertyField {

    private int houses;
    private boolean hotel = false;

    BuildingProperty(String name, int id, int price, int rent) {
        super(name, id, price, rent);
    }

    @Override
    public int calcRent() {
        if (hotel) {
            return (int) Math.round(rent*70/10)*10;
        }
        switch (houses) {
            case 1:
                return (int) Math.round(rent*5/10)*10;
            case 2:
                return (int) Math.round(rent*15/10)*10;
            case 3:
                return (int) Math.round(rent*40/10)*10;
            case 4:
            return (int) Math.round(rent*55/10)*10;

            default:
                return rent;
        }
    }

    public boolean buildHouse() {
        if (houses < 4) {
            houses++;
            return true;
        }
        return false;
    }

    public boolean buildHotel() {
        if (hotel) {
            return false;
        }
        hotel = true;
        return true;
    }
    
    public boolean removeHouse() {
        if (houses == 0) {
            return false;
        }
        houses--;
        return true;
    }

    public boolean removeHotel() {
        if (!hotel) {
            return false;
        }
        hotel = false;
        return true;
    }

    @Override
    public void accept(Player player) {
        player.visit(this);
    }
}
