import Foundation

extension Card {

    enum Symbol: Int, CaseIterable, Comparable, Codable {

        case ass = 1
        case zehn = 2
        case könig = 3
        case ober = 4
        case unter = 5
        case neun = 6
        case acht = 7
        case sieben = 8

        init?(id: Character) {
            switch id {
            case "A": self = .ass
            case "Z": self = .zehn
            case "K": self = .könig
            case "O": self = .ober
            case "U": self = .unter
            case "9": self = .neun
            case "8": self = .acht
            case "7": self = .sieben
            default:
                return nil
            }
        }

        var id: Character {
            switch self {
            case .ass: return "A"
            case .zehn: return "Z"
            case .könig: return "K"
            case .ober: return "O"
            case .unter: return "U"
            case .neun: return "9"
            case .acht: return "8"
            case .sieben: return "7"
            }
        }

        var points: Int {
            switch self {
            case .ass:
                return 11
            case .zehn:
                return 10
            case .könig:
                return 4
            case .ober:
                return 3
            case .unter:
                return 2
            default:
                return 0
            }
        }

        var isTrumpOrAce: Bool {
            switch self {
            case .ass, .ober, .unter:
                return true
            default:
                return false
            }
        }

        static func < (lhs: Card.Symbol, rhs: Card.Symbol) -> Bool {
            lhs.rawValue < rhs.rawValue
        }

    }

}
