import BlueStackSDK

class RNRequestOptions {
    private static let TAG = "RNRequestOptions"
    static func getRequestOptions(optionsJSON: String) -> RequestOptions {
        var requestOptions = RequestOptions()
        do {
            if let data = optionsJSON.data(using: .utf8),
               let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] {
                if let age = json["age"] as? Int {
                    requestOptions.age = age
                }
                if let consentFlag = json["consentFlag"] as? Int {
                    requestOptions.consentFlag = consentFlag
                }
//                if let language = json["language"] as? String {
//                    requestOptions.language = language
//                }
                if let keyword = json["keyword"] as? String {
                    requestOptions.keyword = keyword
                }
                if let contentUrl = json["contentUrl"] as? String {
                    requestOptions.contentUrl = contentUrl
                }
                if let genderStr = json["gender"] as? String {
                    switch genderStr {
                    case "Female":
                        requestOptions.gender = .female
                    case "Male":
                        requestOptions.gender = .male
                    default:
                        requestOptions.gender = .unknown
                    }
                }
                if let locationDict = json["location"] as? [String: Any],
                   let latitude = locationDict["latitude"] as? Double,
                   let longitude = locationDict["longitude"] as? Double,
                   let provider = locationDict["provider"] as? String {
                    let location = CLLocation(latitude: latitude, longitude: longitude)
                    requestOptions.location = location
                }
//                if let adChoicePosition = json["adChoicePosition"] as? Int {
//                    requestOptions.adChoicePosition = adChoicePosition
//                }
            }
        } catch {
            BlueStackLogger.error(tag: TAG, message: "Error parsing request options: \(error)")
        }
        return requestOptions
    }
}
