package org.academiadecodigo.carcrash.cars;

import org.academiadecodigo.carcrash.field.Position;

/**
 * MIT License
 * (c) 2017 Ricardo Constantino
 */

public class Teleporter extends Car {
    private Status status;

    public Teleporter() {
        super(CarType.TELEPORTER, new Position());
        resetCooldown();
    }

    public enum Status {
        DISAPPEARED(0, " "),
        IMPLODED(1, "·"),
        IMPLODING(2, "*"),
        CHARGING(3, "t"),
        INITIAL(4, "T");

        private int level;
        private String symbol;

        Status(int level, String name) {
            this.level = level;
            this.symbol = name;
        }

        public int getLevel() {
            return this.level;
        }

        @Override
        public String toString() {
            return this.symbol;
        }

        public Status next() {
            return Status.values()[getLevel()-1];
        }
    }

    private void resetCooldown() {
        this.status = Status.INITIAL;
    }

    @Override
    public void move() {
        if (isCrashed()) { return; }

        if (getPos().equals(getFinalDestination())) {
            setNewFinalDestination();
        }

        switch(this.status) {
            case DISAPPEARED:
                this.getPos().moveTo(getFinalDestination());
                resetCooldown();
                break;
            default:
                this.status = this.status.next();
        }

    }

    @Override
    public String toString() {
        return isCrashed() ? "C" : this.status.toString();
    }
}
