/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

import Foundation
import XCTest
import azureSwiftRuntime

class ModelFlatteningTests: XCTestCase {

    let timeout: TimeInterval = 102.0
    var azureClient: AzureClient!

    var flattenedProduct1: FlattenedProductProtocol?
    var flattenedProduct2: FlattenedProductProtocol?
    var flattenedProduct3: FlattenedProductProtocol?

    var resource1: ResourceProtocol?
    var resource2: ResourceProtocol?

    var flattenedProduct4: FlattenedProductProtocol?
    var flattenedProduct5: FlattenedProductProtocol?

    override func setUp() {
        continueAfterFailure = false

        let env = AuzureEnvironment(endpoints:[
            .resourceManager : "http://localhost:3000"
        ])

        let atc = AzureTokenCredentials(environment: env, tenantId: "", subscriptionId: "")

        self.azureClient = AzureClient(atc: atc)
            .withRequestInterceptor(LogRequestInterceptor(showOptions: .all))
            .withResponseInterceptor(LogResponseInterceptor(showOptions: .all))

        flattenedProduct1 = FlattenedProductData()
        flattenedProduct1?.id = "1"
        flattenedProduct1?.location = "Building 44"
        flattenedProduct1?.name = "Resource1"
        flattenedProduct1?.properties = FlattenedProductPropertiesData()
        flattenedProduct1?.properties?.provisioningState = "Succeeded"
        flattenedProduct1?.properties?.provisioningStateValues = ProvisioningStateValues.OK
        flattenedProduct1?.properties?.pname = "Product1"
        flattenedProduct1?.properties?.type = "Flat"
        flattenedProduct1?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct1?.type = "Microsoft.Web/sites"

        flattenedProduct2 = FlattenedProductData()
        flattenedProduct2?.id = "2"
        flattenedProduct2?.location = "Building 44"
        flattenedProduct2?.name = "Resource2"

        flattenedProduct3 = FlattenedProductData()
        flattenedProduct3?.id = "3"
        flattenedProduct3?.name = "Resource3"

        // ===

        resource1 = ResourceData()
        resource1?.location = "West US"
        resource1?.tags = ["tag1":"value1","tag2":"value3"]

        resource2 = ResourceData()
        resource2?.location = "Building 44"

        // ===

        flattenedProduct4 = FlattenedProductData()
        flattenedProduct4?.location = "West US"
        flattenedProduct4?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.pname = "Product1"
        flattenedProduct4?.properties?.type = "Flat"

        flattenedProduct5 = FlattenedProductData()
        flattenedProduct5?.location = "Building 44"
        flattenedProduct5?.properties = FlattenedProductPropertiesData()
        flattenedProduct5?.properties?.pname = "Product2"
        flattenedProduct5?.properties?.type = "Flat"

        super.setUp()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func test_putArray() {
        print("\n=================== #1.1 putArray\n")

        let cmd = ModelFlatteningNamespace.PutArrayCommand()
        cmd.resourceArray = [resource1, resource2]

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNil(res)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_getArray() {
        print("\n=================== #1.2 getArray\n")

        let cmd = ModelFlatteningNamespace.GetArrayCommand()
        let expectedResult = [flattenedProduct1, flattenedProduct2, flattenedProduct3]

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNotNil(res)
            for i in 0..<expectedResult.count {
                XCTAssertEqual(expectedResult[i]?.id, res![i]?.id)
            }
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

/* === Not implemented on the server side

    func test_putWrappedArray() {
        print("\n=================== #2.1 putWrappedArray\n")

        let cmd = ModelFlatteningNamespace.PutWrappedArrayCommand()

    func test_getWrappedArray() {
        print("\n=================== #2.2 getWrappedArray\n")

        let cmd = ModelFlatteningNamespace.GetWrappedArrayCommand()
    }
*/

    func test_putDictionary() {
        print("\n=================== #3.1 putDictionary\n")

        let cmd = ModelFlatteningNamespace.PutDictionaryCommand()
        cmd.resourceDictionary = [
            "Resource1" : flattenedProduct4,
            "Resource2" : flattenedProduct5,
        ]

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNil(res)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_getDictionary() {
        print("\n=================== #3.2 getDictionary\n")

        let cmd = ModelFlatteningNamespace.GetDictionaryCommand()
        let expectedResult = [
            "Product1" : flattenedProduct1,
            "Product2" : flattenedProduct2,
            "Product3" : flattenedProduct3
        ]

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNotNil(res)
            for (key, value) in expectedResult {
                XCTAssertEqual(value?.id, res![key]??.id)
                XCTAssertEqual(value?.name, res![key]??.name)
                XCTAssertEqual(value?.location, res![key]??.location)
            }

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_putResourceCollection() {
        print("\n=================== #3.1 putResourceCollection\n")

        var flattenedProduct1: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct1?.location = "West US"
        flattenedProduct1?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct1?.properties = FlattenedProductPropertiesData()
        flattenedProduct1?.properties?.pname = "Product1"
        flattenedProduct1?.properties?.type = "Flat"

        var flattenedProduct2: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct2?.location = "East US"
        flattenedProduct2?.properties = FlattenedProductPropertiesData()
        flattenedProduct2?.properties?.pname = "Product2"
        flattenedProduct2?.properties?.type = "Flat"

        var flattenedProduct3: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct3?.location = "Building 44"
        flattenedProduct3?.properties = FlattenedProductPropertiesData()
        flattenedProduct3?.properties?.pname = "Product2"
        flattenedProduct3?.properties?.type = "Flat"

        var flattenedProduct4: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct4?.location = "India"
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.pname = "Azure"
        flattenedProduct4?.properties?.type = "Flat"

        let cmd = ModelFlatteningNamespace.PutResourceCollectionCommand()
        cmd.resourceComplexObject = ResourceCollectionData()

        cmd.resourceComplexObject?.arrayofresources = [flattenedProduct1, flattenedProduct2]

        cmd.resourceComplexObject?.dictionaryofresources = [
            "Resource1" : flattenedProduct1,
            "Resource2" : flattenedProduct3,
        ]

        cmd.resourceComplexObject?.productresource = flattenedProduct4

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNil(res)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_getResourceCollection() {
        print("\n=================== #3.2 getResourceCollection\n")

        var flattenedProduct4: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct4?.id = "4"
        flattenedProduct4?.location = "Building 44"
        flattenedProduct4?.name = "Resource4"
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.provisioningState = "Succeeded"
        flattenedProduct4?.properties?.provisioningStateValues = ProvisioningStateValues.OK
        flattenedProduct4?.properties?.pname = "Product4"
        flattenedProduct4?.properties?.type = "Flat"
        flattenedProduct4?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct4?.type = "Microsoft.Web/sites"

        var flattenedProduct5: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct5?.id = "5"
        flattenedProduct5?.location = "Building 44"
        flattenedProduct5?.name = "Resource5"

        var flattenedProduct6: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct6?.id = "6"
        flattenedProduct6?.name = "Resource6"

        var flattenedProduct7: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct7?.id = "7"
        flattenedProduct7?.location = "Building 44"
        flattenedProduct7?.name = "Resource7"

        let cmd = ModelFlatteningNamespace.GetResourceCollectionCommand()
        var expectedResult = ResourceCollectionData()
        expectedResult.dictionaryofresources = [
            "Product1" : flattenedProduct1,
            "Product2" : flattenedProduct2,
            "Product3" : flattenedProduct3,
        ]
        expectedResult.arrayofresources = [flattenedProduct4, flattenedProduct5, flattenedProduct6]
        expectedResult.productresource = flattenedProduct7

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNotNil(res)

            XCTAssertNotNil(res!.dictionaryofresources)
            guard let dict = res!.dictionaryofresources else {
                XCTFail(); return
            }
            for (key, value) in expectedResult.dictionaryofresources! {
                guard let keyExists = dict[key], let valNotNil = keyExists else {
                    XCTFail(); return
                }
                XCTAssertEqual(value?.id, valNotNil.id)
                XCTAssertEqual(value?.name, valNotNil.name)
                XCTAssertEqual(value?.location, valNotNil.location)
            }

            XCTAssertNotNil(res!.arrayofresources)
            guard let array = res!.arrayofresources else {
                XCTFail(); return
            }

            for i in 0 ..< expectedResult.arrayofresources!.count {
                XCTAssertEqual(array[i]?.id, expectedResult.arrayofresources![i]?.id)
                XCTAssertEqual(array[i]?.name, expectedResult.arrayofresources![i]?.name)
                XCTAssertEqual(array[i]?.location, expectedResult.arrayofresources![i]?.location)
            }

            guard let resource = expectedResult.productresource else {
                XCTFail(); return
            }

            XCTAssertEqual(expectedResult.productresource?.id, resource.id)
            XCTAssertEqual(expectedResult.productresource?.name, resource.name)
            XCTAssertEqual(expectedResult.productresource?.location, resource.location)

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func testAsync_putResourceCollection() {
        print("\n=================== #3.1 putResourceCollection\n")

        var flattenedProduct1: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct1?.location = "West US"
        flattenedProduct1?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct1?.properties = FlattenedProductPropertiesData()
        flattenedProduct1?.properties?.pname = "Product1"
        flattenedProduct1?.properties?.type = "Flat"

        var flattenedProduct2: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct2?.location = "East US"
        flattenedProduct2?.properties = FlattenedProductPropertiesData()
        flattenedProduct2?.properties?.pname = "Product2"
        flattenedProduct2?.properties?.type = "Flat"

        var flattenedProduct3: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct3?.location = "Building 44"
        flattenedProduct3?.properties = FlattenedProductPropertiesData()
        flattenedProduct3?.properties?.pname = "Product2"
        flattenedProduct3?.properties?.type = "Flat"

        var flattenedProduct4: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct4?.location = "India"
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.pname = "Azure"
        flattenedProduct4?.properties?.type = "Flat"

        let cmd = ModelFlatteningNamespace.PutResourceCollectionCommand()
        cmd.resourceComplexObject = ResourceCollectionData()

        cmd.resourceComplexObject?.arrayofresources = [flattenedProduct1, flattenedProduct2]

        cmd.resourceComplexObject?.dictionaryofresources = [
            "Resource1" : flattenedProduct1,
            "Resource2" : flattenedProduct3,
        ]

        cmd.resourceComplexObject?.productresource = flattenedProduct4

        cmd.executeAsync(client: self.azureClient) {
            res, error in
            XCTAssertNil(error)
            XCTAssertNil(res)
        }
    }

    func testAsync_getResourceCollection() {
        print("\n=================== #3.2 getResourceCollection\n")

        var flattenedProduct4: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct4?.id = "4"
        flattenedProduct4?.location = "Building 44"
        flattenedProduct4?.name = "Resource4"
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.provisioningState = "Succeeded"
        flattenedProduct4?.properties?.provisioningStateValues = ProvisioningStateValues.OK
        flattenedProduct4?.properties?.pname = "Product4"
        flattenedProduct4?.properties?.type = "Flat"
        flattenedProduct4?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct4?.type = "Microsoft.Web/sites"

        var flattenedProduct5: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct5?.id = "5"
        flattenedProduct5?.location = "Building 44"
        flattenedProduct5?.name = "Resource5"

        var flattenedProduct6: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct6?.id = "6"
        flattenedProduct6?.name = "Resource6"

        var flattenedProduct7: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct7?.id = "7"
        flattenedProduct7?.location = "Building 44"
        flattenedProduct7?.name = "Resource7"

        let cmd = ModelFlatteningNamespace.GetResourceCollectionCommand()

        var expectedResult = ResourceCollectionData()
        expectedResult.dictionaryofresources = [
            "Product1" : flattenedProduct1,
            "Product2" : flattenedProduct2,
            "Product3" : flattenedProduct3,
        ]
        expectedResult.arrayofresources = [flattenedProduct4, flattenedProduct5, flattenedProduct6]
        expectedResult.productresource = flattenedProduct7

        cmd.executeAsync(client: self.azureClient) {

            (res: ResourceCollectionProtocol?, error: Error?) in

            XCTAssertNotNil(res)
            XCTAssertNil(error)
            XCTAssertNotNil(res!.dictionaryofresources)
            guard let dict = res!.dictionaryofresources else {
                XCTFail(); return
            }
            for (key, value) in expectedResult.dictionaryofresources! {
                guard let keyExists = dict[key], let valNotNil = keyExists else {
                    XCTFail(); return
                }
                XCTAssertEqual(value?.id, valNotNil.id)
                XCTAssertEqual(value?.name, valNotNil.name)
                XCTAssertEqual(value?.location, valNotNil.location)
            }

            XCTAssertNotNil(res!.arrayofresources)
            guard let array = res!.arrayofresources else {
                XCTFail(); return
            }

            for i in 0 ..< expectedResult.arrayofresources!.count {
                XCTAssertEqual(array[i]?.id, expectedResult.arrayofresources![i]?.id)
                XCTAssertEqual(array[i]?.name, expectedResult.arrayofresources![i]?.name)
                XCTAssertEqual(array[i]?.location, expectedResult.arrayofresources![i]?.location)
            }

            guard let resource = expectedResult.productresource else {
                XCTFail(); return
            }

            XCTAssertEqual(expectedResult.productresource?.id, resource.id)
            XCTAssertEqual(expectedResult.productresource?.name, resource.name)
            XCTAssertEqual(expectedResult.productresource?.location, resource.location)
        }
    }

}


/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

import Foundation
import XCTest
import azureSwiftRuntime

class ModelFlatteningTestsXML: XCTestCase {

    let timeout: TimeInterval = 102.0
    var azureClient: AzureClient!

    var flattenedProduct1: FlattenedProductProtocol?
    var flattenedProduct2: FlattenedProductProtocol?
    var flattenedProduct3: FlattenedProductProtocol?

    var resource1: ResourceProtocol?
    var resource2: ResourceProtocol?

    var flattenedProduct4: FlattenedProductProtocol?
    var flattenedProduct5: FlattenedProductProtocol?

    override func setUp() {
        continueAfterFailure = false

        let env = AuzureEnvironment(endpoints:[
            .resourceManager : "http://localhost:3000"
        ])

        let atc = AzureTokenCredentials(environment: env, tenantId: "", subscriptionId: "")

        self.azureClient = AzureClient(atc: atc)
            .withRequestInterceptor(LogRequestInterceptor(showOptions: .all))
            .withResponseInterceptor(LogResponseInterceptor(showOptions: .all))

        flattenedProduct1 = FlattenedProductData()
        flattenedProduct1?.id = "1"
        flattenedProduct1?.location = "Building 44"
        flattenedProduct1?.name = "Resource1"
        flattenedProduct1?.properties = FlattenedProductPropertiesData()
        flattenedProduct1?.properties?.provisioningState = "Succeeded"
        flattenedProduct1?.properties?.provisioningStateValues = ProvisioningStateValues.OK
        flattenedProduct1?.properties?.pname = "Product1"
        flattenedProduct1?.properties?.type = "Flat"
        flattenedProduct1?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct1?.type = "Microsoft.Web/sites"

        flattenedProduct2 = FlattenedProductData()
        flattenedProduct2?.id = "2"
        flattenedProduct2?.location = "Building 44"
        flattenedProduct2?.name = "Resource2"

        flattenedProduct3 = FlattenedProductData()
        flattenedProduct3?.id = "3"
        flattenedProduct3?.name = "Resource3"

        // ===

        resource1 = ResourceData()
        resource1?.location = "West US"
        resource1?.tags = ["tag1":"value1","tag2":"value3"]

        resource2 = ResourceData()
        resource2?.location = "Building 44"

        // ===

        flattenedProduct4 = FlattenedProductData()
        flattenedProduct4?.location = "West US"
        flattenedProduct4?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.pname = "Product1"
        flattenedProduct4?.properties?.type = "Flat"

        flattenedProduct5 = FlattenedProductData()
        flattenedProduct5?.location = "Building 44"
        flattenedProduct5?.properties = FlattenedProductPropertiesData()
        flattenedProduct5?.properties?.pname = "Product2"
        flattenedProduct5?.properties?.type = "Flat"

        super.setUp()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testSingleItemArrayOrMap() {
        do {
            let string = "Hello"
            let xmlString = xmlSingleItemCollection.replacingOccurrences(of: "$", with: string)
            let res = try XMLDecoder().decode(SingleItemCollection<String>?.self, from: xmlString.data(using: .utf8)!)
            XCTAssertNotNil(res)
            XCTAssertEqual(string, res!.arrayType[0])
            XCTAssertEqual(string, res!.mapType["val"])
            XCTAssertEqual(string, res!.arrayTypeOp[0])
            XCTAssertEqual(string, res!.mapTypeOp["val"]!)
            XCTAssertEqual(nil, res!.arrayTypeOpEmpty[0])
            XCTAssertNil(res!.mapTypeOpEmpty["val"]!)
            XCTAssertEqual(nil, res!.mapTypeOpEmpty["val"]!)
            XCTAssertEqual(string, res!.arrayOpTypeOp?[0])
            XCTAssertEqual(string, res!.mapOpTypeOp?["val"]!)

            let val = 12345.2345
            let xmlInt = xmlSingleItemCollection.replacingOccurrences(of: "$", with: "\(val)")
            let resInt = try XMLDecoder().decode(SingleItemCollection<Double>?.self, from: xmlInt.data(using: .utf8)!)
            XCTAssertNotNil(res)
            XCTAssertEqual(val, resInt!.arrayType[0])
            XCTAssertEqual(val, resInt!.mapType["val"])
            XCTAssertEqual(val, resInt!.arrayTypeOp[0])
            XCTAssertEqual(val, resInt!.mapTypeOp["val"]!)
            XCTAssertEqual(nil, res!.arrayTypeOpEmpty[0])
            XCTAssertNil(res!.mapTypeOpEmpty["val"]!)
            XCTAssertEqual(nil, resInt!.mapTypeOpEmpty["val"]!)
            XCTAssertEqual(val, resInt!.arrayOpTypeOp?[0])
            XCTAssertEqual(val, resInt!.mapOpTypeOp?["val"]!)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func testVariousTypesXML() {
        print("\n=================== #0 VariousTypesXML\n")

        do {
            let res = try XMLDecoder().decode(VariousTypesXML?.self, from: xmlVariousTypes.data(using: .utf8)!)
            XCTAssertNotNil(res)
            XCTAssertEqual(9223372036854775806, res!.dictionaryOfInt?["big"])
            XCTAssertEqual(18446744073709551614, res!.dictionaryOfUInt?["big"])
            XCTAssertEqual(3.402823e+37, res!.dictionaryOfFloat?["big"])
            XCTAssertEqual(2.225073858507201e-307, res!.dictionaryOfDouble?["big"])
            XCTAssertEqual("Aa23$$", (res!.dictionaryOfString?["random"])!)
            XCTAssertEqual(nil, (res!.dictionaryOfString?["empty"])!)
            XCTAssertEqual(true, res!.dictionaryOfBool?["hi"])
            XCTAssertEqual(18446744073709551615, res!.arrayOfUInt?.first)

            XCTAssertEqual(127, res!.dictionaryOfInt8?["biggest"])
            XCTAssertEqual(32767, res!.dictionaryOfInt16?["biggest"])
            XCTAssertEqual(-2147483648, res!.dictionaryOfInt32?["smallest"])
            XCTAssertEqual(-9223372036854775808, res!.dictionaryOfInt64?["smallest"])

            XCTAssertEqual(255, res!.dictionaryOfUInt8?["biggest"])
            XCTAssertEqual(65535, res!.dictionaryOfUInt16?["biggest"])
            XCTAssertEqual(4294967295, res!.dictionaryOfUInt32?["biggest"])
            XCTAssertEqual(18446744073709551615, res!.dictionaryOfUInt64?["biggest"])

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func testNullValuesXML() {
        print("\n=================== #0 NullValuesXML\n")

        do {
            let dateFormatter = DateFormatter()
            dateFormatter.dateFormat = "EEE, dd MMM yyyy HH:mm:ssZ"
            let xmlDecoder = XMLDecoder()
            xmlDecoder.dateDecodingStrategy = .formatted(dateFormatter)

            let res = try xmlDecoder.decode(NullValuesXML?.self, from: xmlNullValuesXML.data(using: .utf8)!)
            XCTAssertNotNil(res)
            XCTAssertNil(res!.int)
            XCTAssertNil(res!.string)
            XCTAssertNil(res!.float)
            XCTAssertNil(res!.double)
            XCTAssertNil(res!.bool)
            XCTAssertNil(res!.date)

            XCTAssertEqual(45689, res!.int1)
            XCTAssertEqual("AS23@#", res!.string1)
            XCTAssertEqual(1.12345, res!.float1)
            XCTAssertEqual(1.123456789012345, res!.double1)
            XCTAssertEqual(true, res!.bool1)

            if let date = res!.date {
                let calendar = Calendar.current
                let components = calendar.dateComponents(in: TimeZone(identifier: "GMT")!, from: date)
                XCTAssertEqual(2018, components.year)
                XCTAssertEqual(1, components.month)
                XCTAssertEqual(18, components.day)
                XCTAssertEqual(2, components.hour)
                XCTAssertEqual(1, components.minute)
                XCTAssertEqual(17, components.second)
                XCTAssertEqual(5, components.weekday)
            }

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

/*
    func test_putArray() {
        print("\n=================== #1.1 putArray\n")

        let cmd = ModelFlatteningNamespace.PutArrayCommand()
        cmd.resourceArray = [resource1, resource2]

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNil(res)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }
*/
    func test_getArray() {
        print("\n=================== #1.2 getArray\n")

        //let cmd = ModelFlatteningNamespace.GetArrayCommand()
        let expectedResult = [flattenedProduct1, flattenedProduct2, flattenedProduct3]

        do {
            let res = try XMLDecoder().decode([FlattenedProductData?]?.self, from: xmlArray.data(using: .utf8)!)
            XCTAssertNotNil(res)
            for i in 0..<expectedResult.count {
                XCTAssertEqual(expectedResult[i]?.id, res![i]?.id)
                XCTAssertEqual(expectedResult[i]?.name, res![i]?.name)
                XCTAssertEqual(expectedResult[i]?.location, res![i]?.location)
                XCTAssertEqual(expectedResult[i]?.type, res![i]?.type)
            }
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

/*
    func test_putDictionary() {
        print("\n=================== #3.1 putDictionary\n")

        let cmd = ModelFlatteningNamespace.PutDictionaryCommand()
        cmd.resourceDictionary = [
            "Resource1" : flattenedProduct4,
            "Resource2" : flattenedProduct5,
        ]

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNil(res)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }
 */
    func test_getDictionary() {
        print("\n=================== #3.2 getDictionary\n")

        //let cmd = ModelFlatteningNamespace.GetDictionaryCommand()
        let expectedResult = [
            "Product1" : flattenedProduct1,
            "Product2" : flattenedProduct2,
            "Product3" : flattenedProduct3
        ]

        do {
            let res = try XMLDecoder().decode([String:FlattenedProductData?]?.self, from: xmlDictionary.data(using: .utf8)!)
            XCTAssertNotNil(res)
            for (key, value) in expectedResult {
                XCTAssertEqual(value?.id, res![key]??.id)
                XCTAssertEqual(value?.name, res![key]??.name)
                XCTAssertEqual(value?.location, res![key]??.location)
            }

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

/*
    func test_putResourceCollection() {
        print("\n=================== #3.1 putResourceCollection\n")

        var flattenedProduct1: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct1?.location = "West US"
        flattenedProduct1?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct1?.properties = FlattenedProductPropertiesData()
        flattenedProduct1?.properties?.pname = "Product1"
        flattenedProduct1?.properties?.type = "Flat"

        var flattenedProduct2: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct2?.location = "East US"
        flattenedProduct2?.properties = FlattenedProductPropertiesData()
        flattenedProduct2?.properties?.pname = "Product2"
        flattenedProduct2?.properties?.type = "Flat"

        var flattenedProduct3: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct3?.location = "Building 44"
        flattenedProduct3?.properties = FlattenedProductPropertiesData()
        flattenedProduct3?.properties?.pname = "Product2"
        flattenedProduct3?.properties?.type = "Flat"

        var flattenedProduct4: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct4?.location = "India"
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.pname = "Azure"
        flattenedProduct4?.properties?.type = "Flat"

        let cmd = ModelFlatteningNamespace.PutResourceCollectionCommand()
        cmd.resourceComplexObject = ResourceCollectionData()

        cmd.resourceComplexObject?.arrayofresources = [flattenedProduct1, flattenedProduct2]

        cmd.resourceComplexObject?.dictionaryofresources = [
            "Resource1" : flattenedProduct1,
            "Resource2" : flattenedProduct3,
        ]

        cmd.resourceComplexObject?.productresource = flattenedProduct4

        do {
            let res = try cmd.execute(client: self.azureClient)
            XCTAssertNil(res)
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }
 */
    func test_getResourceCollection() {
        print("\n=================== #3.2 getResourceCollection\n")

        var flattenedProduct4: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct4?.id = "4"
        flattenedProduct4?.location = "Building 44"
        flattenedProduct4?.name = "Resource4"
        flattenedProduct4?.properties = FlattenedProductPropertiesData()
        flattenedProduct4?.properties?.provisioningState = "Succeeded"
        flattenedProduct4?.properties?.provisioningStateValues = ProvisioningStateValues.OK
        flattenedProduct4?.properties?.pname = "Product4"
        flattenedProduct4?.properties?.type = "Flat"
        flattenedProduct4?.tags = ["tag1":"value1","tag2":"value3"]
        flattenedProduct4?.type = "Microsoft.Web/sites"

        var flattenedProduct5: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct5?.id = "5"
        flattenedProduct5?.location = "Building 44"
        flattenedProduct5?.name = "Resource5"

        var flattenedProduct6: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct6?.id = "6"
        flattenedProduct6?.name = "Resource6"

        var flattenedProduct7: FlattenedProductProtocol? = FlattenedProductData()
        flattenedProduct7?.id = "7"
        flattenedProduct7?.location = "Building 44"
        flattenedProduct7?.name = "Resource7"

        //let cmd = ModelFlatteningNamespace.GetResourceCollectionCommand()
        var expectedResult = ResourceCollectionData()
        expectedResult.dictionaryofresources = [
            "Product1" : flattenedProduct1,
            "Product2" : flattenedProduct2,
            "Product3" : flattenedProduct3,
        ]
        expectedResult.arrayofresources = [flattenedProduct4, flattenedProduct5, flattenedProduct6]
        expectedResult.productresource = flattenedProduct7

        do {
            let res = try XMLDecoder().decode(ResourceCollectionData?.self, from: xmlResourceCollection.data(using: .utf8)!)

            XCTAssertNotNil(res!.dictionaryofresources)
            guard let dict = res!.dictionaryofresources else {
                XCTFail(); return
            }
            for (key, value) in expectedResult.dictionaryofresources! {
                guard let keyExists = dict[key], let valNotNil = keyExists else {
                    XCTFail(); return
                }
                XCTAssertEqual(value?.id, valNotNil.id)
                XCTAssertEqual(value?.name, valNotNil.name)
                XCTAssertEqual(value?.location, valNotNil.location)
            }

            XCTAssertNotNil(res!.arrayofresources)
            guard let array = res!.arrayofresources else {
                XCTFail(); return
            }

            for i in 0 ..< expectedResult.arrayofresources!.count {
                XCTAssertEqual(array[i]?.id, expectedResult.arrayofresources![i]?.id)
                XCTAssertEqual(array[i]?.name, expectedResult.arrayofresources![i]?.name)
                XCTAssertEqual(array[i]?.location, expectedResult.arrayofresources![i]?.location)
            }

            guard let resource = expectedResult.productresource else {
                XCTFail(); return
            }

            XCTAssertEqual(expectedResult.productresource?.id, resource.id)
            XCTAssertEqual(expectedResult.productresource?.name, resource.name)
            XCTAssertEqual(expectedResult.productresource?.location, resource.location)

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }
}


/**
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 */

import Foundation
import XCTest
import azureSwiftRuntime

class PagingTests: XCTestCase {

    let timeout: TimeInterval = 102.0
    var azureClient: AzureClient!

    override func setUp() {
        continueAfterFailure = false

        let env = AuzureEnvironment(endpoints:[
            .resourceManager : "http://localhost:3000"
            ])

        let atc = AzureTokenCredentials(environment: env, tenantId: "", subscriptionId: "")

        self.azureClient = AzureClient(atc: atc)
            .withRequestInterceptor(LogRequestInterceptor(showOptions: .all))
            .withResponseInterceptor(LogResponseInterceptor(showOptions: .all))

        super.setUp()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func checkResult(_ res: ProductResultProtocol?) {
        XCTAssertNotNil(res)
        guard let values = res?.values else {
            XCTFail()
            return
        }

        for value in values {
            let properties = value?.properties
            XCTAssertNotNil(properties?.id)
            XCTAssertNotNil(properties?.name)
        }
    }

    func checkResult(_ res: OdataProductResultProtocol?) {
        XCTAssertNotNil(res)
        guard let values = res?.values else {
            XCTFail()
            return
        }

        for value in values {
            let properties = value?.properties
            XCTAssertNotNil(properties?.id)
            XCTAssertNotNil(properties?.name)
        }
    }

    func test_Paging_getSinglePages() {
        print("\n=================== #1 Paging_getSinglePages\n")

        let cmd = PagingNamespace.GetSinglePagesCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            XCTFail(error.localizedDescription)
            print("=== Error:", error)
        }
    }

    func test_Paging_getMultiplePages() {
        print("\n=================== #2 Paging_getMultiplePages\n")

        let cmd = PagingNamespace.GetMultiplePagesCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            XCTFail(error.localizedDescription)
            print("=== Error:", error)
        }
    }

    func test_Paging_getOdataMultiplePages() {
        print("\n=================== #3 Paging_getOdataMultiplePages\n")

        let cmd = PagingNamespace.GetOdataMultiplePagesCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            XCTFail(error.localizedDescription)
            print("=== Error:", error)
        }
    }

    func test_Paging_getMultiplePagesWithOffset() {
        print("\n=================== #4 Paging_getMultiplePagesWithOffset\n")

        let cmd = PagingNamespace.GetMultiplePagesWithOffsetCommand()
        // FIXME: should it be mandatory on has default value
        cmd.offset = 1

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_Paging_getMultiplePagesRetryFirst() {
        print("\n=================== #5 Paging_getMultiplePagesRetryFirst\n")

        let cmd = PagingNamespace.GetMultiplePagesRetryFirstCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_Paging_getMultiplePagesRetrySecond() {
        print("\n=================== #6 Paging_getMultiplePagesRetrySecond\n")

        let cmd = PagingNamespace.GetMultiplePagesRetrySecondCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_Paging_getSinglePagesFailure() {
        print("\n=================== #7 Paging_getSinglePagesFailure\n")

        let cmd = PagingNamespace.GetSinglePagesFailureCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch RuntimeError.errorStatusCode(_, let data) {
            if let error = AzureErrorDecoder<CloudError>(mimeType: .json).decode(data: data) {
                let status = error.status
                let message = error.message
                XCTAssertEqual(status, 400)
                XCTAssertEqual(message, "Expected single failure test.")
            } else {
                XCTFail("Can't parse error data")
            }
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_Paging_getMultiplePagesFailure() {
        print("\n=================== #7 Paging_getMultiplePagesFailure\n")

        let cmd = PagingNamespace.GetMultiplePagesFailureCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch RuntimeError.errorStatusCode(_, let data) {
            if let error = AzureErrorDecoder<CloudError>(mimeType: .json).decode(data: data) {
                let status = error.status
                let message = error.message
                XCTAssertEqual(status, 400)
                XCTAssertEqual(message, "Expected single failure test.")
            } else {
                XCTFail("Can't parse error data")
            }
        } catch {
            print("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func test_Paging_getMultiplePagesFailureUri() {
        print("\n=================== #7 Paging_getMultiplePagesFailureUri\n")

        let cmd = PagingNamespace.GetMultiplePagesFailureUriCommand()

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            print("=== Error:", error)
            let e = error as NSError
            XCTAssertNotNil(e.userInfo["NSErrorFailingURLStringKey"])
            XCTAssertNotNil(e.userInfo["NSErrorFailingURLKey"])
        }
    }

    func test_Paging_getMultiplePagesFragmentNextLink() {
        print("\n=================== #7 Paging_getMultiplePagesFragmentNextLink\n")

        let cmd = PagingNamespace.GetMultiplePagesFragmentNextLinkCommand()
        // TODO: the test-server waits for these specific values, but thay are not specified in the swagger
        cmd.tenant = "test_user"
        cmd.apiVersion="1.6"
        // TODO: the test-server waits for the 'api_version' (with underscore) query param (should be 'api-version' (with dash))

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            print("=== Error:", error)
            let e = error as NSError
            XCTAssertNotNil(e.userInfo["NSErrorFailingURLStringKey"])
            XCTAssertNotNil(e.userInfo["NSErrorFailingURLKey"])
        }
    }

    func test_Paging_getMultiplePagesFragmentWithGroupingNextLink() {
        print("\n=================== #8 Paging_getMultiplePagesFragmentWithGroupingNextLink\n")

        let cmd = PagingNamespace.GetMultiplePagesFragmentWithGroupingNextLinkCommand()
        cmd.tenant = "test_user"
        cmd.apiVersion="1.6"

        do {
            var res = try cmd.getFirstPage(client: self.azureClient)
            checkResult(res)

            while let next = try cmd.getNextPage(from: res, client: self.azureClient) {
                checkResult(next)
                res = next
            }

        } catch {
            print("=== Error:", error)
            let e = error as NSError
            XCTAssertNotNil(e.userInfo["NSErrorFailingURLStringKey"])
            XCTAssertNotNil(e.userInfo["NSErrorFailingURLKey"])
        }
    }
}


//
//  JustArrayXML.swift
//  azureSwiftRuntime
//
//  Created by Vladimir Shcherbakov on 1/26/18.
//

import Foundation
import XCTest
import azureSwiftRuntime

class TopLevelXMLTests: XCTestCase {

    override func setUp() {
        super.setUp()
    }

    override func tearDown() {
        // Put teardown code here. This method is called after the invocation of each test method in the class.
        super.tearDown()
    }

    func testTopLevelArray() {
        do {
            let res = try XMLDecoder().decode([Int?]?.self, from: xmlTopLevelArray.data(using: .utf8)!)
            if let array = res {
                for val in array {
                    print (val ?? "-")
                }
            } else {
                print("Array is empty")
            }

        } catch {
            print ("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }

    func testTopLevelArrayOfBooks() {
        do {
            let res = try XMLDecoder().decode([Book?]?.self, from: xmlTopLevelArrayOfBooks.data(using: .utf8)!)
            if let books = res {
                for book in books {
                    print ("id: ", book?.id ?? "-")
                    print ("name: ", book?.name ?? "-")
                }
            } else {
                print("Array is empty")
            }

        } catch {
            print ("=== Error:", error)
            XCTFail(error.localizedDescription)
        }
    }
}


// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// Bool is the test Infrastructure for AutoRest
import Foundation
import azureSwiftRuntime
struct BoolNamespace {
    // GetFalse get false Boolean value
    public class GetFalseCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/bool/false"
        }

        public override func preCall()  {
        }

        override func returnFunc(data: Data) throws -> Decodable? {
            return try CoderFactory.decoder(for: .json).decode(Bool?.self, from: data) as Decodable
        }

        public func execute(client: RuntimeClient) throws -> Bool? {
            return try client.execute(command: self) as! Bool?
        }
    }

    // GetInvalid get invalid Boolean value
    public class GetInvalidCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/bool/invalid"
        }

        public override func preCall()  {
        }

        override func returnFunc(data: Data) throws -> Decodable? {
            return try CoderFactory.decoder(for: .json).decode(Bool?.self, from: data) as Decodable
        }

        public func execute(client: RuntimeClient) throws -> Bool? {
            return try client.execute(command: self) as! Bool?
        }
    }

    // GetNull get null Boolean value
    public class GetNullCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/bool/null"
        }

        public override func preCall()  {
        }

        override func returnFunc(data: Data) throws -> Decodable? {
            return try CoderFactory.decoder(for: .json).decode(Bool?.self, from: data) as Decodable
        }

        public func execute(client: RuntimeClient) throws -> Bool? {
            return try client.execute(command: self) as! Bool?
        }
    }

    // GetTrue get true Boolean value
    public class GetTrueCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/bool/true"
        }

        public override func preCall()  {
        }

        override func returnFunc(data: Data) throws -> Decodable? {
            return try CoderFactory.decoder(for: .json).decode(Bool?.self, from: data) as Decodable
        }

        public func execute(client: RuntimeClient) throws -> Bool? {
            return try client.execute(command: self) as! Bool?
        }
    }

    // PutFalse set Boolean value false
    public class PutFalseCommand : BaseCommand {
        public var boolBody :  Bool?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/bool/false"
            self.headerParameters = ["Content-Type":"application/json"]
        }

        public override func preCall()  {
            self.body = boolBody as Codable
        }

        public override func encodeBody() throws -> Data? {
            return try CoderFactory.encoder(for: .json).encode(boolBody)
        }

        public func execute(client: RuntimeClient) throws -> Decodable? {
            return try client.execute(command: self)
        }
    }

    // PutTrue set Boolean value true
    public class PutTrueCommand : BaseCommand {
        public var boolBody :  Bool?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/bool/true"
            self.headerParameters = ["Content-Type":"application/json"]
        }

        public override func preCall()  {
            self.body = boolBody as Codable
        }

        public override func encodeBody() throws -> Data? {
            return try CoderFactory.encoder(for: .json).encode(boolBody);
        }

        public func execute(client: RuntimeClient) throws -> Decodable? {
            return try client.execute(command: self)
        }
    }

}


// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// Date is the test Infrastructure for AutoRest
import Foundation
import azureSwiftRuntime
struct DateNamespace {
    // GetInvalidDate get invalid date value
    public class GetInvalidDateCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/date/invaliddate"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result, error) in
                completionHandler(result, error)
            }
        }
    }

    // GetMaxDate get max date value 9999-12-31
    public class GetMaxDateCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/date/max"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result, error) in
                completionHandler(result, error)
            }
        }
    }

    // GetMinDate get min date value 0000-01-01
    public class GetMinDateCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/date/min"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result, error) in
                completionHandler(result, error)
            }
        }
    }

    // GetNull get null date value
    public class GetNullCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/date/null"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result, error) in
                completionHandler(result, error)
            }
        }
    }

    // GetOverflowDate get overflow date value
    public class GetOverflowDateCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/date/overflowdate"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient, completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result, error) in
                completionHandler(result, error)
            }
        }
    }

    // GetUnderflowDate get underflow date value
    public class GetUnderflowDateCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/date/underflowdate"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Data?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result, error) in
                completionHandler(result, error)
            }
        }
    }

    // PutMaxDate put max date value 9999-12-31
    public class PutMaxDateCommand : BaseCommand {
        public var dateBody : Date?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/date/max"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
            self.body = dateBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let dateBodyString = DateConverter.toString(date: dateBody, format: .date)
                let encodedValue = try encoder.encode(dateBodyString)
                return encodedValue
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                error in
                completionHandler(error)
            }
        }
    }

    // PutMinDate put min date value 0000-01-01
    public class PutMinDateCommand : BaseCommand {
        public var dateBody :  Date?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/date/min"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
            self.body = dateBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let dateBodyString = DateConverter.toString(date: dateBody, format: .date)
                let encodedValue = try encoder.encode(dateBodyString)
                return encodedValue
            }
            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                error in
                completionHandler(error)
            }
        }
    }
}


// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// Datetime is the test Infrastructure for AutoRest
import Foundation
import azureSwiftRuntime
struct Datetime {
    // GetInvalid get invalid datetime value
    public class GetInvalidCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/invalid"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTime)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetLocalNegativeOffsetLowercaseMaxDateTime get max datetime value with positive num offset
    // 9999-12-31t23:59:59.9999999-14:00
    public class GetLocalNegativeOffsetLowercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/localnegativeoffset/lowercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetLocalNegativeOffsetMinDateTime get min datetime value 0001-01-01T00:00:00-14:00
    public class GetLocalNegativeOffsetMinDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/min/localnegativeoffset"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetLocalNegativeOffsetUppercaseMaxDateTime get max datetime value with positive num offset
    // 9999-12-31T23:59:59.9999999-14:00
    public class GetLocalNegativeOffsetUppercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/localnegativeoffset/uppercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetLocalPositiveOffsetLowercaseMaxDateTime get max datetime value with positive num offset
    // 9999-12-31t23:59:59.9999999+14:00
    public class GetLocalPositiveOffsetLowercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/localpositiveoffset/lowercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetLocalPositiveOffsetMinDateTime get min datetime value 0001-01-01T00:00:00+14:00
    public class GetLocalPositiveOffsetMinDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/min/localpositiveoffset"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetLocalPositiveOffsetUppercaseMaxDateTime get max datetime value with positive num offset
    // 9999-12-31T23:59:59.9999999+14:00
    public class GetLocalPositiveOffsetUppercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/localpositiveoffset/uppercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetNull get null datetime value
    public class GetNullCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/null"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                return try decoder.decode(String?.self, from: data)
            }
            throw DecodeError.unknownMimeType
        }
        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetOverflow get overflow datetime value
    public class GetOverflowCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/overflow"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTime)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUnderflow get underflow datetime value
    public class GetUnderflowCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/underflow"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTime)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUtcLowercaseMaxDateTime get max datetime value 9999-12-31t23:59:59.9999999z
    public class GetUtcLowercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/utc/lowercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTime)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUtcMinDateTime get min datetime value 0001-01-01T00:00:00Z
    public class GetUtcMinDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/min/utc"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTime)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUtcUppercaseMaxDateTime get max datetime value 9999-12-31T23:59:59.9999999Z
    public class GetUtcUppercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/utc/uppercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTime)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // PutLocalNegativeOffsetMaxDateTime put max datetime value with positive numoffset 9999-12-31t23:59:59.9999999-14:00
    public class PutLocalNegativeOffsetMaxDateTimeCommand : BaseCommand {
        public var datetimeBody :  String??

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/localnegativeoffset"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let encodedValue = try encoder.encode(datetimeBody)
                return encodedValue
            }
            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

    // PutLocalNegativeOffsetMinDateTime put min datetime value 0001-01-01T00:00:00-14:00
    public class PutLocalNegativeOffsetMinDateTimeCommand : BaseCommand {
        public var datetimeBody :  String??

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetime/min/localnegativeoffset"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let encodedValue = try encoder.encode(datetimeBody)
                return encodedValue
            }
            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

    // PutLocalPositiveOffsetMaxDateTime put max datetime value with positive numoffset 9999-12-31t23:59:59.9999999+14:00
    public class PutLocalPositiveOffsetMaxDateTimeCommand : BaseCommand {
        public var datetimeBody :  String??

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/localpositiveoffset"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let encodedValue = try encoder.encode(datetimeBody)
                return encodedValue
            }
            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

    // PutLocalPositiveOffsetMinDateTime put min datetime value 0001-01-01T00:00:00+14:00
    public class PutLocalPositiveOffsetMinDateTimeCommand : BaseCommand {
        public var datetimeBody :  String??

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetime/min/localpositiveoffset"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let encodedValue = try encoder.encode(datetimeBody)
                return encodedValue
            }
            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

    // PutUtcMaxDateTime put max datetime value 9999-12-31T23:59:59.9999999Z
    public class PutUtcMaxDateTimeCommand : BaseCommand {
        public var datetimeBody :  Date?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetime/max/utc"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
            self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let dateBodyString = DateConverter.toString(date: datetimeBody, format: .dateTime)
                let encodedValue = try encoder.encode(dateBodyString)
                return encodedValue
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

    // PutUtcMinDateTime put min datetime value 0001-01-01T00:00:00Z
    public class PutUtcMinDateTimeCommand : BaseCommand {
        public var datetimeBody :  Date?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetime/min/utc"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let dateBodyString = DateConverter.toString(date: datetimeBody, format: .dateTime)
                let encodedValue = try encoder.encode(dateBodyString)
                return encodedValue
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

}


// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// Datetimerfc1123 is the test Infrastructure for AutoRest
import Foundation
import azureSwiftRuntime
struct Datetimerfc1123 {
    // GetInvalid get invalid datetime value
    public class GetInvalidCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/invalid"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (String?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: String?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetNull get null datetime value
    public class GetNullCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/null"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetOverflow get overflow datetime value
    public class GetOverflowCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/overflow"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUnderflow get underflow datetime value
    public class GetUnderflowCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/underflow"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .date)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUtcLowercaseMaxDateTime get max datetime value fri, 31 dec 9999 23:59:59 gmt
    public class GetUtcLowercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/max/lowercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTimeRfc1123)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUtcMinDateTime get min datetime value Mon, 1 Jan 0001 00:00:00 GMT
    public class GetUtcMinDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/min"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
    }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTimeRfc1123)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // GetUtcUppercaseMaxDateTime get max datetime value FRI, 31 DEC 9999 23:59:59 GMT
    public class GetUtcUppercaseMaxDateTimeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/max/uppercase"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let decoder = try CoderFactory.decoder(for: mimeType)
                let dataString = try decoder.decode(String?.self, from: data)
                return DateConverter.fromString(dateStr: dataString, format: .dateTimeRfc1123)
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Date?, Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (result: Date?, error: Error?) in
                completionHandler(result, error)
            }
        }
    }

    // PutUtcMaxDateTime put max datetime value Fri, 31 Dec 9999 23:59:59 GMT
    public class PutUtcMaxDateTimeCommand : BaseCommand {
        public var datetimeBody :  Date?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/max"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let dateBodyString = DateConverter.toString(date: datetimeBody, format: .dateTimeRfc1123)
                let encodedValue = try encoder.encode(dateBodyString)
                return encodedValue
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

    // PutUtcMinDateTime put min datetime value Mon, 1 Jan 0001 00:00:00 GMT
    public class PutUtcMinDateTimeCommand : BaseCommand {
        public var datetimeBody :  Date?

        public override init() {
            super.init()
            self.method = "Put"
            self.isLongRunningOperation = false
            self.path = "/datetimerfc1123/min"
            self.headerParameters = ["Content-Type":"application/json; charset=utf-8"]
        }

        public override func preCall()  {
        self.body = datetimeBody
        }

        public override func encodeBody() throws -> Data? {
            let contentType = "application/json"
            if let mimeType = MimeType.getType(forStr: contentType) {
                let encoder = try CoderFactory.encoder(for: mimeType)
                let dateBodyString = DateConverter.toString(date: datetimeBody, format: .dateTimeRfc1123)
                let encodedValue = try encoder.encode(dateBodyString)
                return encodedValue
            }

            throw DecodeError.unknownMimeType
        }

        public func execute(client: RuntimeClient,
            completionHandler: @escaping (Error?) -> Void) -> Void {
            client.executeAsync(command: self) {
                (error) in
                completionHandler(error)
            }
        }
    }

}


// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is regenerated.

// Files is the test Infrastructure for AutoRest Swagger BAT
import Foundation
import azureSwiftRuntime
struct FilesNamespace {
    // GetEmptyFile get empty file
    public class GetEmptyFileCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/files/stream/empty"
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            return data
        }

        public func execute(client: RuntimeClient) throws -> Data? {
            return try client.execute(command: self) as! Data?
        }
    }

    // GetFile get file
    public class GetFileCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/files/stream/nonempty"
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            return data
        }

        public func execute(client: RuntimeClient) throws -> Data? {
            return try client.execute(command: self) as! Data?
        }
    }

    // GetFileLarge get a large file
    public class GetFileLargeCommand : BaseCommand {

        public override init() {
            super.init()
            self.method = "Get"
            self.isLongRunningOperation = false
            self.path = "/files/stream/verylarge"
        }

        public override func preCall()  {
        }

        public override func returnFunc(data: Data) throws -> Decodable? {
            return data
        }

        public func execute(client: RuntimeClient) throws -> Data? {
            return try client.execute(command: self) as! Data?
        }
    }

}