// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
import Foundation
import azureSwiftRuntime
internal struct ComputeNodeData : ComputeNodeProtocol {
    public var id: String?
    public var url: String?
    public var state: ComputeNodeStateEnum?
    public var schedulingState: SchedulingStateEnum?
    public var stateTransitionTime: Date?
    public var lastBootTime: Date?
    public var allocationTime: Date?
    public var ipAddress: String?
    public var affinityId: String?
    public var vmSize: String?
    public var totalTasksRun: Int32?
    public var runningTasksCount: Int32?
    public var totalTasksSucceeded: Int32?
    public var recentTasks: [TaskInformationProtocol?]?
    public var startTask: StartTaskProtocol?
    public var startTaskInfo: StartTaskInformationProtocol?
    public var certificateReferences: [CertificateReferenceProtocol?]?
    public var errors: [ComputeNodeErrorProtocol?]?
    public var isDedicated: Bool?
    public var endpointConfiguration: ComputeNodeEndpointConfigurationProtocol?

        enum CodingKeys: String, CodingKey {case id = "id"
        case url = "url"
        case state = "state"
        case schedulingState = "schedulingState"
        case stateTransitionTime = "stateTransitionTime"
        case lastBootTime = "lastBootTime"
        case allocationTime = "allocationTime"
        case ipAddress = "ipAddress"
        case affinityId = "affinityId"
        case vmSize = "vmSize"
        case totalTasksRun = "totalTasksRun"
        case runningTasksCount = "runningTasksCount"
        case totalTasksSucceeded = "totalTasksSucceeded"
        case recentTasks = "recentTasks"
        case startTask = "startTask"
        case startTaskInfo = "startTaskInfo"
        case certificateReferences = "certificateReferences"
        case errors = "errors"
        case isDedicated = "isDedicated"
        case endpointConfiguration = "endpointConfiguration"
        }

  public init()  {
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
      if container.contains(.id) {
        self.id = try container.decode(String?.self, forKey: .id)
    }
    if container.contains(.url) {
        self.url = try container.decode(String?.self, forKey: .url)
    }
    if container.contains(.state) {
        self.state = try container.decode(ComputeNodeStateEnum?.self, forKey: .state)
    }
    if container.contains(.schedulingState) {
        self.schedulingState = try container.decode(SchedulingStateEnum?.self, forKey: .schedulingState)
    }
    if container.contains(.stateTransitionTime) {
        self.stateTransitionTime = DateConverter.fromString(dateStr: (try container.decode(String?.self, forKey: .stateTransitionTime)), format: .dateTime)
    }
    if container.contains(.lastBootTime) {
        self.lastBootTime = DateConverter.fromString(dateStr: (try container.decode(String?.self, forKey: .lastBootTime)), format: .dateTime)
    }
    if container.contains(.allocationTime) {
        self.allocationTime = DateConverter.fromString(dateStr: (try container.decode(String?.self, forKey: .allocationTime)), format: .dateTime)
    }
    if container.contains(.ipAddress) {
        self.ipAddress = try container.decode(String?.self, forKey: .ipAddress)
    }
    if container.contains(.affinityId) {
        self.affinityId = try container.decode(String?.self, forKey: .affinityId)
    }
    if container.contains(.vmSize) {
        self.vmSize = try container.decode(String?.self, forKey: .vmSize)
    }
    if container.contains(.totalTasksRun) {
        self.totalTasksRun = try container.decode(Int32?.self, forKey: .totalTasksRun)
    }
    if container.contains(.runningTasksCount) {
        self.runningTasksCount = try container.decode(Int32?.self, forKey: .runningTasksCount)
    }
    if container.contains(.totalTasksSucceeded) {
        self.totalTasksSucceeded = try container.decode(Int32?.self, forKey: .totalTasksSucceeded)
    }
    if container.contains(.recentTasks) {
        self.recentTasks = try container.decode([TaskInformationData?]?.self, forKey: .recentTasks)
    }
    if container.contains(.startTask) {
        self.startTask = try container.decode(StartTaskData?.self, forKey: .startTask)
    }
    if container.contains(.startTaskInfo) {
        self.startTaskInfo = try container.decode(StartTaskInformationData?.self, forKey: .startTaskInfo)
    }
    if container.contains(.certificateReferences) {
        self.certificateReferences = try container.decode([CertificateReferenceData?]?.self, forKey: .certificateReferences)
    }
    if container.contains(.errors) {
        self.errors = try container.decode([ComputeNodeErrorData?]?.self, forKey: .errors)
    }
    if container.contains(.isDedicated) {
        self.isDedicated = try container.decode(Bool?.self, forKey: .isDedicated)
    }
    if container.contains(.endpointConfiguration) {
        self.endpointConfiguration = try container.decode(ComputeNodeEndpointConfigurationData?.self, forKey: .endpointConfiguration)
    }
    if var pageDecoder = decoder as? PageDecoder  {
      if pageDecoder.isPagedData,
        let nextLinkName = pageDecoder.nextLinkName {
          pageDecoder.nextLink = try UnknownCodingKey.decodeStringForKey(decoder: decoder, keyForDecode: nextLinkName)
      }
    }
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    if self.id != nil {try container.encode(self.id, forKey: .id)}
    if self.url != nil {try container.encode(self.url, forKey: .url)}
    if self.state != nil {try container.encode(self.state, forKey: .state)}
    if self.schedulingState != nil {try container.encode(self.schedulingState, forKey: .schedulingState)}
    if self.stateTransitionTime != nil {
        try container.encode(DateConverter.toString(date: self.stateTransitionTime!, format: .dateTime), forKey: .stateTransitionTime)
    }
    if self.lastBootTime != nil {
        try container.encode(DateConverter.toString(date: self.lastBootTime!, format: .dateTime), forKey: .lastBootTime)
    }
    if self.allocationTime != nil {
        try container.encode(DateConverter.toString(date: self.allocationTime!, format: .dateTime), forKey: .allocationTime)
    }
    if self.ipAddress != nil {try container.encode(self.ipAddress, forKey: .ipAddress)}
    if self.affinityId != nil {try container.encode(self.affinityId, forKey: .affinityId)}
    if self.vmSize != nil {try container.encode(self.vmSize, forKey: .vmSize)}
    if self.totalTasksRun != nil {try container.encode(self.totalTasksRun, forKey: .totalTasksRun)}
    if self.runningTasksCount != nil {try container.encode(self.runningTasksCount, forKey: .runningTasksCount)}
    if self.totalTasksSucceeded != nil {try container.encode(self.totalTasksSucceeded, forKey: .totalTasksSucceeded)}
    if self.recentTasks != nil {try container.encode(self.recentTasks as! [TaskInformationData?]?, forKey: .recentTasks)}
    if self.startTask != nil {try container.encode(self.startTask as! StartTaskData?, forKey: .startTask)}
    if self.startTaskInfo != nil {try container.encode(self.startTaskInfo as! StartTaskInformationData?, forKey: .startTaskInfo)}
    if self.certificateReferences != nil {try container.encode(self.certificateReferences as! [CertificateReferenceData?]?, forKey: .certificateReferences)}
    if self.errors != nil {try container.encode(self.errors as! [ComputeNodeErrorData?]?, forKey: .errors)}
    if self.isDedicated != nil {try container.encode(self.isDedicated, forKey: .isDedicated)}
    if self.endpointConfiguration != nil {try container.encode(self.endpointConfiguration as! ComputeNodeEndpointConfigurationData?, forKey: .endpointConfiguration)}
  }
}

extension DataFactory {
  public static func createComputeNodeProtocol() -> ComputeNodeProtocol {
    return ComputeNodeData()
  }
}
