 /**
     Used to send Push notifications via a IBM Cloud Push Notifications service.
 */
-public struct PushNotifications {
+public class PushNotifications {
     
     
     /// The IBM Cloud region where the Push Notifications service is hosted.

    }
    
    
    internal let headers: [String: String]
    private let httpResource: HttpResource
    private let httpBulkResource: HttpResource

    // used to test in test zone and dev zone
    public static var overrideServerHost = "";

        }
    }
    
    /**
     Initialize PushNotifications by supplying the information needed to connect to the IBM Cloud Push Notifications service.
     
     - parameter pushRegion: The IBM Cloud region where the Push Notifications service is hosted.
     - parameter pushAppGuid: The app GUID for the IBM Cloud application that the Push Notifications service is bound to.
     - parameter pushApiKey: The ApiKey credential required for Push Notifications service authorization.
     */
    public init(pushApiKey:String, pushAppGuid: String, pushRegion: String) {
        
        self.pushApiKey = pushApiKey
        self.pushAppRegion = pushRegion
        if(PushNotifications.overrideServerHost.isEmpty) {
            let pushHost = "imfpush." + pushRegion
            
            httpResource = HttpResource(schema: "https", host: pushHost, port: "443", path: "/imfpush/v1/apps/\(pushAppGuid)/messages")
            httpBulkResource = HttpResource(schema: "https", host: pushHost, port: "443", path: "/imfpush/v1/apps/\(pushAppGuid)/messages/bulk")
        } else {
            let url = URL(string: PushNotifications.overrideServerHost)
            httpResource = HttpResource(schema: (url?.scheme)!, host: (url?.host)!, path: "/imfpush/v1/apps/\(pushAppGuid)/messages")
            httpBulkResource = HttpResource(schema: (url?.scheme)!, host: (url?.host)!, path: "/imfpush/v1/apps/\(pushAppGuid)/messages/bulk")
        }
    }
    
    
    /**
     This method will get an iam auth token from the server and add it to the request header. Get Auth token before calling any send methods. 
     - parameter completionHandler: Returns true if there is token with token string
    */
    public func getAuthToken(completionHandler: @escaping (_ hasToken:Bool?, _ tokenValue: String) -> Void) {
        if (pushApiKey != "" && pushAppRegion != "") {
            
            var regionString = pushAppRegion;
            if (!PushNotifications.overrideServerHost.isEmpty) {
                let url = URL(string: PushNotifications.overrideServerHost)
                let domain = url?.host
                if let splitStringArray = domain?.split(separator: ".", maxSplits: 1, omittingEmptySubsequences: true) {
                    regionString = String(splitStringArray[1])
                }
            }
            let pushHost = "iam." + regionString
            let iamHttpResource = HttpResource(schema: "https", host: pushHost, port: "443", path: "/identity/token")
            
            var data:Data?
            let dataString =  "grant_type=urn:ibm:params:oauth:grant-type:apikey&apikey=\(pushApiKey)"
            
            data = dataString.data(using: .ascii, allowLossyConversion: true)
            
            let iamHeaders = ["Content-Type":"application/x-www-form-urlencoded","Accept":"application/json"]
            
            HttpClient.post(resource: iamHttpResource, headers: iamHeaders, data: data) { (error, status, headers, data) in
                
                //completionHandler?(data,status,PushNotificationsError.from(httpError: error))
                if(status == 200) {
                    
                    let dataJson = try! JSONSerialization.jsonObject(with: data!, options:JSONSerialization.ReadingOptions.allowFragments) as! NSDictionary
                    let tokenString = dataJson.value(forKey: "access_token") as? String
                    if !(tokenString?.isEmpty)! {
                        self.headers = ["Authorization": "Bearer " + tokenString!, "Content-Type": "application/json"]
                    }
                    completionHandler(true, tokenString!)
                } else {
                    print("Error While getting the token", error ?? "")
                    completionHandler(false, "")
                }
            }
        } else {
            print("Error : Pass valid Apikey and app region")
            completionHandler(false, "")
        }
    }

    /**
        Send the Push notification. 
     
