// 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 ComputeNodeUserData : ComputeNodeUserProtocol {
    public var name: String
    public var isAdmin: Bool?
    public var expiryTime: Date?
    public var password: String?
    public var sshPublicKey: String?

        enum CodingKeys: String, CodingKey {case name = "name"
        case isAdmin = "isAdmin"
        case expiryTime = "expiryTime"
        case password = "password"
        case sshPublicKey = "sshPublicKey"
        }

  public init(name: String)  {
    self.name = name
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
      self.name = try container.decode(String.self, forKey: .name)
    if container.contains(.isAdmin) {
        self.isAdmin = try container.decode(Bool?.self, forKey: .isAdmin)
    }
    if container.contains(.expiryTime) {
        self.expiryTime = DateConverter.fromString(dateStr: (try container.decode(String?.self, forKey: .expiryTime)), format: .dateTime)
    }
    if container.contains(.password) {
        self.password = try container.decode(String?.self, forKey: .password)
    }
    if container.contains(.sshPublicKey) {
        self.sshPublicKey = try container.decode(String?.self, forKey: .sshPublicKey)
    }
    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)
    try container.encode(self.name, forKey: .name)
    if self.isAdmin != nil {try container.encode(self.isAdmin, forKey: .isAdmin)}
    if self.expiryTime != nil {
        try container.encode(DateConverter.toString(date: self.expiryTime!, format: .dateTime), forKey: .expiryTime)
    }
    if self.password != nil {try container.encode(self.password, forKey: .password)}
    if self.sshPublicKey != nil {try container.encode(self.sshPublicKey, forKey: .sshPublicKey)}
  }
}

extension DataFactory {
  public static func createComputeNodeUserProtocol(name: String) -> ComputeNodeUserProtocol {
    return ComputeNodeUserData(name: name)
  }
}
