import Foundation

struct StreamFeature: Stateable {
    let featureName: String
    let required: Bool
    var isProcessed: Bool
    var additionalInfo: String?

    init(_ name: String, _ required: Bool, _additionalInfo: String? = nil) {
        featureName = name
        self.required = required
        isProcessed = false
        additionalInfo = _additionalInfo
    }
}

extension StreamFeature {
    // less number = more priority
    var priority: Int {
        switch featureName {
        case "starttls":
            return 0

        case "mechanism":
            guard let mechanismName = additionalInfo else { return 20 }
            switch mechanismName {
            case "SCRAM-SHA-1":
                return 21

            case "PLAIN":
                return 22

            default:
                return 20
            }

        case "bind":
            return 30

        default:
            return 100
        }
    }
}
