import Foundation

/// The string id of a game
typealias GameId = String

enum GameType: String, CaseIterable, Codable {
    
    case rufEichel = "ruf-eichel"
    case rufBlatt = "ruf-blatt"
    case rufSchelln = "ruf-schelln"
    case hochzeit = "hochzeit"
    case bettel = "bettel"
    case wenz = "wenz"
    case geier = "geier"
    case soloEichel = "solo-eichel"
    case soloBlatt = "solo-blatt"
    case soloHerz = "solo-herz"
    case soloSchelln = "solo-schelln"

    init?(id: GameId) {
        self.init(rawValue: id)
    }

    var isCall: Bool {
        switch self {
        case .rufEichel, .rufBlatt, .rufSchelln:
            return true
        default:
            return false
        }
    }

    var calledSuit: Card.Suit? {
        switch self {
        case .rufEichel:
            return .eichel
        case .rufBlatt:
            return .blatt
        case .rufSchelln:
            return .schelln
        default:
            return nil
        }
    }

    var isSingleGame: Bool {
        switch self {
        case .rufEichel, .rufBlatt, .rufSchelln, .hochzeit:
            return false
        default:
            return true
        }
    }
    
    var basicCost: Int {
        gameClass.cost
    }

    var sortingType: CardOrder.Type {
        switch self {
        case .wenz:
            return WenzCardOrder.self
        case .geier:
            return GeierCardOrder.self
        case .soloEichel:
            return SoloEichelCardOrder.self
        case .soloBlatt:
            return SoloBlattCardOrder.self
        case .soloSchelln:
            return SoloSchellnCardOrder.self
        default:
            return NormalCardOrder.self
        }
    }
}

extension GameType: GameConvertible {

    var id: GameId {
        rawValue
    }
    
}
