// Code generated by sidekick. DO NOT EDIT.
//
// Copyright 2026 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

import Foundation
import GoogleCloudWkt

/// Describes a subordinate CA's issuers. This is either a resource name to a
/// known issuing
/// [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority],
/// or a PEM issuer certificate chain.
///
/// [google.cloud.security.privateca.v1.CertificateAuthority]: <doc:CertificateAuthority>
public struct SubordinateConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  public var subordinateConfig: OneOf_SubordinateConfig? = nil

  /// Initialize a new instance of `SubordinateConfig`.
  public init() {}

  /// Use `config` to return a new instance of this object, with some fields updated.
  ///
  /// Commonly used to initialize the value, for example:
  ///
  /// ```
  /// let value = SubordinateConfig().with { $0.certificateAuthority = ... }
  /// ```
  public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
    var copy = self
    try config(&copy)
    return copy
  }

  private enum CodingKeys: Swift.String, CodingKey {
    case certificateAuthority = "certificateAuthority"
    case pemIssuerChain = "pemIssuerChain"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)

    var subordinateConfig: OneOf_SubordinateConfig? = nil
    let subordinateConfigCheckAndSet = {
      if subordinateConfig != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'subordinateConfig'"))
      }
      subordinateConfig = $0
    }
    if let certificateAuthority = try container.decodeIfPresent(
      Swift.String.self, forKey: .certificateAuthority)
    {
      try subordinateConfigCheckAndSet(.certificateAuthority(certificateAuthority))
    }
    if let pemIssuerChain = try container.decodeIfPresent(
      SubordinateConfig.SubordinateConfigChain?.self, forKey: .pemIssuerChain)
    {
      try subordinateConfigCheckAndSet(.pemIssuerChain(pemIssuerChain))
    }
    self.subordinateConfig = subordinateConfig
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)

    if let choice = self.subordinateConfig {
      switch choice {
      case .certificateAuthority(let value):
        try container.encode(value, forKey: .certificateAuthority)
      case .pemIssuerChain(let value):
        try container.encode(value, forKey: .pemIssuerChain)
      }
    }
  }

  /// This message describes a subordinate CA's issuer certificate chain. This
  /// wrapper exists for compatibility reasons.
  public struct SubordinateConfigChain: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. Expected to be in leaf-to-root order according to RFC 5246.
    public var pemCertificates: [Swift.String] = []

    /// Initialize a new instance of `SubordinateConfigChain`.
    public init() {}

    /// Use `config` to return a new instance of this object, with some fields updated.
    ///
    /// Commonly used to initialize the value, for example:
    ///
    /// ```
    /// let value = SubordinateConfigChain().with { $0.pemCertificates = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    public static var _anyTypeUrl: Swift.String {
      return
        "type.googleapis.com/google.cloud.security.privateca.v1.SubordinateConfig.SubordinateConfigChain"
    }
    public init(fromAny any: GoogleCloudWkt.`Any`) throws {
      self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
    }
    public func _pack() throws -> GoogleCloudWkt.Struct {
      return try GoogleCloudWkt._slowAnySerialize(message: self)
    }
  }

  public enum OneOf_SubordinateConfig: Codable, Equatable, Sendable {
    /// Required. This can refer to a
    /// [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority]
    /// that was used to create a subordinate
    /// [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority].
    /// This field is used for information and usability purposes only. The
    /// resource name is in the format
    /// `projects/*/locations/*/caPools/*/certificateAuthorities/*`.
    ///
    /// [google.cloud.security.privateca.v1.CertificateAuthority]: <doc:CertificateAuthority>
    case certificateAuthority(Swift.String)
    /// Required. Contains the PEM certificate chain for the issuers of this
    /// [CertificateAuthority][google.cloud.security.privateca.v1.CertificateAuthority],
    /// but not pem certificate for this CA itself.
    ///
    /// [google.cloud.security.privateca.v1.CertificateAuthority]: <doc:CertificateAuthority>
    indirect case pemIssuerChain(SubordinateConfig.SubordinateConfigChain?)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.cloud.security.privateca.v1.SubordinateConfig"
  }
  public init(fromAny any: GoogleCloudWkt.`Any`) throws {
    self = try GoogleCloudWkt._slowAnyDeserialize(Self.self, from: any)
  }
  public func _pack() throws -> GoogleCloudWkt.Struct {
    return try GoogleCloudWkt._slowAnySerialize(message: self)
  }
}
