/* Copyright 2018 JDCLOUD.COM

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

     http:#www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   京东云iotcard接口
   iotcard相关接口

   OpenAPI spec version: v1
   Contact: 

   NOTE: This class is auto generated by the jdcloud code generator program.
 */



import Foundation
import JDCloudSDKCore

public class IotcardJDCloudClient:NSObject,JDCloudClient{
    
    private final var iotcardJDCloudClient:IotcardJDCloudClient!


    public convenience init(credential:Credential,sdkEnvironment:SDKEnvironment) {
        self.init()
        self.credential = credential
        self.sdkEnvironment = sdkEnvironment
        iotcardJDCloudClient = self
    }


    public override init() {

        if(GlobalConfig.credential == nil)
        {
            GlobalConfig.credential = Credential(accessKeyId: "",secretAccessKey: "")
        }
        var sdkEnvironment:SDKEnvironment
        if(GlobalConfig.sdkEnvironment != nil)
        {
            sdkEnvironment = GlobalConfig.sdkEnvironment!
        }else{
            sdkEnvironment = SDKEnvironment(endPoint: "openapi.myiot.jdcloud.com");
        }
        self.credential = GlobalConfig.credential!
        self.sdkEnvironment = sdkEnvironment
        super.init()
        iotcardJDCloudClient = self
    }
    
    public let userAgent: String = "JdcloudSdkSwift/" + "0.0.1/" + "iotcard/" + "v1"
    
    public let serviceName: String = "iotcard"
    
    public let version: String = "v1"
    
    public let contentType:String = "application/json"
    
    public var credential: Credential
    
    public var sdkEnvironment: SDKEnvironment
    
    public var customHeader: [String : String] = [String:String]()

    public var httpRequestProtocol: String = "https"

    public func addCustomer(key: String, value: String) {
        customHeader[key] = value
    }



    
    public func onOffStatusAsync(request:OnOffStatusRequest,requestComplation:@escaping ExecuteResult<OnOffStatusResult>) throws {
        iotcardJDCloudClient = self
        try OnOffStatusExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func closeIotFlowAsync(request:CloseIotFlowRequest,requestComplation:@escaping ExecuteResult<CloseIotFlowResult>) throws {
        iotcardJDCloudClient = self
        try CloseIotFlowExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func openIotCardAsync(request:OpenIotCardRequest,requestComplation:@escaping ExecuteResult<OpenIotCardResult>) throws {
        iotcardJDCloudClient = self
        try OpenIotCardExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func openIotFlowAsync(request:OpenIotFlowRequest,requestComplation:@escaping ExecuteResult<OpenIotFlowResult>) throws {
        iotcardJDCloudClient = self
        try OpenIotFlowExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func lifeStatusAsync(request:LifeStatusRequest,requestComplation:@escaping ExecuteResult<LifeStatusResult>) throws {
        iotcardJDCloudClient = self
        try LifeStatusExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func closeIotCardAsync(request:CloseIotCardRequest,requestComplation:@escaping ExecuteResult<CloseIotCardResult>) throws {
        iotcardJDCloudClient = self
        try CloseIotCardExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func gprsRealtimeInfoAsync(request:GprsRealtimeInfoRequest,requestComplation:@escaping ExecuteResult<GprsRealtimeInfoResult>) throws {
        iotcardJDCloudClient = self
        try GprsRealtimeInfoExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }

    
    public func gprsStatusAsync(request:GprsStatusRequest,requestComplation:@escaping ExecuteResult<GprsStatusResult>) throws {
        iotcardJDCloudClient = self
        try GprsStatusExecutor(jdCloudClient: iotcardJDCloudClient).executeAsync(request: request) { (statusCode,result,error,data) in
            requestComplation(statusCode,result,error,data)

        }
    }
    
}


public extension IotcardJDCloudClient{

    convenience init(credential: Credential) {

        var sdkEnvironment:SDKEnvironment
        if(GlobalConfig.sdkEnvironment != nil)
        {
            sdkEnvironment = GlobalConfig.sdkEnvironment!
        }else{
            sdkEnvironment = SDKEnvironment(endPoint: "openapi.myiot.jdcloud.com");
        }
        self.init(credential: credential,sdkEnvironment: sdkEnvironment)
    }
}
