package org.academiadecodigo.bootcamp11.arabiannights.genies;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */
public abstract class Genie {
    private int maxWishes;
    private int wishesGranted;
    private GenieType type;

    public enum GenieType {
        HAPPY("Happy Genie"),
        GRUMPY("Grumpy Genie"),
        RECYCLABLE("Recyclable Demon");

        private String name;

        GenieType(String name) {
            this.name = name;
        }

        @Override
        public String toString() {
            return name;
        }
    }

    Genie(int maxWishes, GenieType type) {
        this.maxWishes = maxWishes;
        this.type = type;
        this.wishesGranted = 0;
    }

    public GenieType getGenieType () {
        return this.type;
    }

    int getMaxWishes() {
        return this.maxWishes;
    }

    public int getWishesLeft() {
        return this.maxWishes - this.wishesGranted;
    }

    public void introduction() {
        System.out.println("\n" + this.type + ": Hello there, I'm a " + this.type +
                           ". I can grant " + (getMaxWishes() > 0 ? getMaxWishes() : "any")  + " wish(es).");
    }

    void grantOneWish(String wish) {
        System.out.println(this.type + ": Granting wish: " + wish);
        this.wishesGranted++;
    }

    public abstract void grantWish(String wish);
}
