import Foundation
import ComplyCubeMobileSDK

public final class WelcomeConsentStageParser: StageParser {
    public init() {}

    public func canParse(_ input: Any) -> Bool { input is [String: Any] }

    public func parse(_ input: Any) throws -> ComplyCubeMobileSDKStage? {
        let map = input as! [String: Any]
        switch (map["name"] as? String) ?? "" {
        case "intro", "welcome":
            let b = WelcomeStageBuilder()
            if let t = map["title"] as? String { _ = b.setTitle(title: t) }
            if let m = map["message"] as? String { _ = b.setMessage(message: m) }
            return b.build()
        case "consent":
            let b = UserConsentStageBuilder()
            if let t = map["title"] as? String { _ = b.setTitle(title: t) }
            if let m = map["message"] as? String { _ = b.setAcceptTitle(title: m) }
            return b.build()
        default:
            return nil
        }
    }
}
