package org.academiadecodigo.enuminatti.fx.calculator;

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

public enum Operation {
    ADD("+"),
    SUBTRACT("-"),
    MULTIPLY("×"),
    DIVIDE("÷"),
    EQUAL("="),
    RESET("C"),
    DELETE("DEL");

    private String id;

    Operation(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

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

    public static Operation getOperation(String symbol) {
        if (symbol == null) {
            return null;
        }

        switch (symbol) {
            case "+":
                return ADD;
            case "-":
                return SUBTRACT;
            case "x":
            case "*":
                return MULTIPLY;
            case "/":
            case ":":
                return DIVIDE;
            case "=":
                return EQUAL;
            case "C":
                return RESET;
            case "DEL":
                return DELETE;
            default:
                return null;
        }
    }

    public boolean isMathOperation() {
        switch (this) {
            case EQUAL:
            case RESET:
            case DELETE:
                return false;
            default:
                return true;
        }
    }
}
