// 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 CertificateReferenceData : CertificateReferenceProtocol {
    public var thumbprint: String
    public var thumbprintAlgorithm: String
    public var storeLocation: CertificateStoreLocationEnum?
    public var storeName: String?
    public var visibility: [CertificateVisibilityEnum?]?

        enum CodingKeys: String, CodingKey {case thumbprint = "thumbprint"
        case thumbprintAlgorithm = "thumbprintAlgorithm"
        case storeLocation = "storeLocation"
        case storeName = "storeName"
        case visibility = "visibility"
        }

  public init(thumbprint: String, thumbprintAlgorithm: String)  {
    self.thumbprint = thumbprint
    self.thumbprintAlgorithm = thumbprintAlgorithm
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
      self.thumbprint = try container.decode(String.self, forKey: .thumbprint)
    self.thumbprintAlgorithm = try container.decode(String.self, forKey: .thumbprintAlgorithm)
    if container.contains(.storeLocation) {
        self.storeLocation = try container.decode(CertificateStoreLocationEnum?.self, forKey: .storeLocation)
    }
    if container.contains(.storeName) {
        self.storeName = try container.decode(String?.self, forKey: .storeName)
    }
    if container.contains(.visibility) {
        self.visibility = try container.decode([CertificateVisibilityEnum?]?.self, forKey: .visibility)
    }
    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.thumbprint, forKey: .thumbprint)
    try container.encode(self.thumbprintAlgorithm, forKey: .thumbprintAlgorithm)
    if self.storeLocation != nil {try container.encode(self.storeLocation, forKey: .storeLocation)}
    if self.storeName != nil {try container.encode(self.storeName, forKey: .storeName)}
    if self.visibility != nil {try container.encode(self.visibility as! [CertificateVisibilityEnum?]?, forKey: .visibility)}
  }
}

extension DataFactory {
  public static func createCertificateReferenceProtocol(thumbprint: String, thumbprintAlgorithm: String) -> CertificateReferenceProtocol {
    return CertificateReferenceData(thumbprint: thumbprint, thumbprintAlgorithm: thumbprintAlgorithm)
  }
}
