import Foundation
import ComplyCubeMobileSDK

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

    public func canParse(_ input: Any) -> Bool {
        guard let m = input as? [String: Any] else { return false }
        return ["face_capture","faceCapture"].contains(m["name"] as? String ?? "")
    }

    public func parse(_ input: Any) throws -> ComplyCubeMobileSDKStage? {
        let s = input as! [String: Any]
        let mode = (s["mode"] as? String) ?? "photo"
        let b = BiometricStageBuilder()
            .setEnableMLAssistant(enable: s["useMLAssistance"] as? Bool ?? true)
            .setShowGuidance(enable: s["showGuidance"] as? Bool ?? true)
            .setRetryLimit(count: s["retryLimit"] as? Int ?? 0)

        if mode == "video" {
            return b.setType(type: .video).build()
        } else {
            return b.setType(type: .photo)
                .useLiveCaptureOnly(enable: s["useLiveCaptureOnly"] as? Bool ?? true)
                .build()
        }
    }
}
