// 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 RecoverableDatabasePropertiesData : RecoverableDatabasePropertiesProtocol {
    public var edition: String?
    public var serviceLevelObjective: String?
    public var elasticPoolName: String?
    public var lastAvailableBackupDate: Date?

        enum CodingKeys: String, CodingKey {case edition = "edition"
        case serviceLevelObjective = "serviceLevelObjective"
        case elasticPoolName = "elasticPoolName"
        case lastAvailableBackupDate = "lastAvailableBackupDate"
        }

  public init()  {
  }

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

extension DataFactory {
  public static func createRecoverableDatabasePropertiesProtocol() -> RecoverableDatabasePropertiesProtocol {
    return RecoverableDatabasePropertiesData()
  }
}
