import Foundation
import ConnatixPlayerSDKObjc

@objc public class ObjcHelper: NSObject {
    
    @objc public static func decodeDataToElementsConfig(data: Data) throws -> CNElementsConfig {
        do {
            return try JSONDecoder().decode(CNElementsConfig.self, from: data)
        } catch {
            throw error as NSError
        }
    }
    
    @objc public static func decodeDataToPlayspaceConfig(data: Data) throws -> CNPlayspaceConfig {
        do {
            return try JSONDecoder().decode(CNPlayspaceConfig.self, from: data)
        } catch {
            throw error as NSError
        }

    }
    
    @objc public static func decodeDataToTrack(data: Data) throws -> CNTrack {
        do {
            return try JSONDecoder().decode(CNTrack.self, from: data)
        } catch {
            throw error as NSError
        }
    }
    
    @objc public static func getEventKey(_ event: CNPlayerEvent) -> NSString {
        return event.type.rawValue as NSString
    }
    
    @objc public static func getVideoQualityNumber(_ videoQuality: CNVideoQuality) -> NSNumber {
        return videoQuality.rawValue as NSNumber
    }

    @objc public static func toObstructionPurpose(_ obstructionPurposeString: NSString) -> CNObstructionPurpose {
        switch obstructionPurposeString {
        case "videoControls": return .videoControls
        case "closeAd": return .closeAd
        case "notVisible": return .notVisible
        default: return .other
        }
    }
}
