package com.marvinelsen.cedict.api

enum class Tone {
    NONE, FIRST, SECOND, THIRD, FORTH, FIFTH;

    companion object {
        fun fromDigit(digit: Char) = when (digit) {
            '1' -> FIRST
            '2' -> SECOND
            '3' -> THIRD
            '4' -> FORTH
            '5' -> FIFTH
            else -> error("Digit $digit is not a valid tone")
        }
    }

    override fun toString() = when (this) {
        NONE -> ""
        FIRST -> "1"
        SECOND -> "2"
        THIRD -> "3"
        FORTH -> "4"
        FIFTH -> "5"
    }
}
