// 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 set of X.509 extensions that may be part of some certificate
/// issuance controls.
public struct CertificateExtensionConstraints: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. A set of named X.509 extensions. Will be combined with
  /// [additional_extensions][google.cloud.security.privateca.v1.CertificateExtensionConstraints.additional_extensions]
  /// to determine the full set of X.509 extensions.
  ///
  /// [google.cloud.security.privateca.v1.CertificateExtensionConstraints.additional_extensions]: <doc:CertificateExtensionConstraints/additionalExtensions>
  public var knownExtensions: [CertificateExtensionConstraints.KnownCertificateExtension] = []

  /// Optional. A set of [ObjectIds][google.cloud.security.privateca.v1.ObjectId]
  /// identifying custom X.509 extensions. Will be combined with
  /// [known_extensions][google.cloud.security.privateca.v1.CertificateExtensionConstraints.known_extensions]
  /// to determine the full set of X.509 extensions.
  ///
  /// [google.cloud.security.privateca.v1.CertificateExtensionConstraints.known_extensions]: <doc:CertificateExtensionConstraints/knownExtensions>
  /// [google.cloud.security.privateca.v1.ObjectId]: <doc:ObjectId>
  public var additionalExtensions: [ObjectId] = []

  /// Initialize a new instance of `CertificateExtensionConstraints`.
  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 = CertificateExtensionConstraints().with { $0.knownExtensions = ... }
  /// ```
  public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
    var copy = self
    try config(&copy)
    return copy
  }

  /// Describes well-known X.509 extensions that can appear in a
  /// [Certificate][google.cloud.security.privateca.v1.Certificate], not
  /// including the
  /// [SubjectAltNames][google.cloud.security.privateca.v1.SubjectAltNames]
  /// extension.
  ///
  /// [google.cloud.security.privateca.v1.Certificate]: <doc:Certificate>
  /// [google.cloud.security.privateca.v1.SubjectAltNames]: <doc:SubjectAltNames>
  public enum KnownCertificateExtension: Codable, Equatable, Sendable {
    /// Not specified.
    case unspecified
    /// Refers to a certificate's Key Usage extension, as described in [RFC 5280
    /// section 4.2.1.3](https://tools.ietf.org/html/rfc5280#section-4.2.1.3).
    /// This corresponds to the
    /// [KeyUsage.base_key_usage][google.cloud.security.privateca.v1.KeyUsage.base_key_usage]
    /// field.
    ///
    /// [google.cloud.security.privateca.v1.KeyUsage.base_key_usage]: <doc:KeyUsage/baseKeyUsage>
    case baseKeyUsage
    /// Refers to a certificate's Extended Key Usage extension, as described in
    /// [RFC 5280
    /// section 4.2.1.12](https://tools.ietf.org/html/rfc5280#section-4.2.1.12).
    /// This corresponds to the
    /// [KeyUsage.extended_key_usage][google.cloud.security.privateca.v1.KeyUsage.extended_key_usage]
    /// message.
    ///
    /// [google.cloud.security.privateca.v1.KeyUsage.extended_key_usage]: <doc:KeyUsage/extendedKeyUsage>
    case extendedKeyUsage
    /// Refers to a certificate's Basic Constraints extension, as described in
    /// [RFC 5280
    /// section 4.2.1.9](https://tools.ietf.org/html/rfc5280#section-4.2.1.9).
    /// This corresponds to the
    /// [X509Parameters.ca_options][google.cloud.security.privateca.v1.X509Parameters.ca_options]
    /// field.
    ///
    /// [google.cloud.security.privateca.v1.X509Parameters.ca_options]: <doc:X509Parameters/caOptions>
    case caOptions
    /// Refers to a certificate's Policy object identifiers, as described in
    /// [RFC 5280
    /// section 4.2.1.4](https://tools.ietf.org/html/rfc5280#section-4.2.1.4).
    /// This corresponds to the
    /// [X509Parameters.policy_ids][google.cloud.security.privateca.v1.X509Parameters.policy_ids]
    /// field.
    ///
    /// [google.cloud.security.privateca.v1.X509Parameters.policy_ids]: <doc:X509Parameters/policyIds>
    case policyIds
    /// Refers to OCSP servers in a certificate's Authority Information Access
    /// extension, as described in
    /// [RFC 5280
    /// section 4.2.2.1](https://tools.ietf.org/html/rfc5280#section-4.2.2.1),
    /// This corresponds to the
    /// [X509Parameters.aia_ocsp_servers][google.cloud.security.privateca.v1.X509Parameters.aia_ocsp_servers]
    /// field.
    ///
    /// [google.cloud.security.privateca.v1.X509Parameters.aia_ocsp_servers]: <doc:X509Parameters/aiaOcspServers>
    case aiaOcspServers
    /// Refers to Name Constraints extension as described in
    /// [RFC 5280
    /// section 4.2.1.10](https://tools.ietf.org/html/rfc5280#section-4.2.1.10)
    case nameConstraints
    /// Encodes an unknown integer value.
    ///
    /// The most common cause for an unknown values is for the service to send
    /// a value unknown to the library. We recommend you update your library to
    /// the latest version.
    case unknownIntValue(Int)
    /// Encodes an unknown string value.
    ///
    /// The most common cause for an unknown values is for the service to send
    /// a value unknown to the library. We recommend you update your library to
    /// the latest version.
    case unknownStringValue(String)

    public init() {
      self = .unspecified
    }

    /// Returns the integer value associated with the enumeration.
    ///
    /// If the enumeration was initialized with an unknown string value, this returns `nil`.
    public var intValue: Int? {
      switch self {
      case .unspecified: return 0
      case .baseKeyUsage: return 1
      case .extendedKeyUsage: return 2
      case .caOptions: return 3
      case .policyIds: return 4
      case .aiaOcspServers: return 5
      case .nameConstraints: return 6
      case .unknownIntValue(let v): return v
      case .unknownStringValue: return nil
      }
    }

    /// Returns the string value (or name) associated with the enumeration.
    ///
    /// If the enumeration was initialized with an unknown integer value, this returns `nil`.
    public var stringValue: Swift.String? {
      switch self {
      case .unspecified: return "KNOWN_CERTIFICATE_EXTENSION_UNSPECIFIED"
      case .baseKeyUsage: return "BASE_KEY_USAGE"
      case .extendedKeyUsage: return "EXTENDED_KEY_USAGE"
      case .caOptions: return "CA_OPTIONS"
      case .policyIds: return "POLICY_IDS"
      case .aiaOcspServers: return "AIA_OCSP_SERVERS"
      case .nameConstraints: return "NAME_CONSTRAINTS"
      case .unknownIntValue: return nil
      case .unknownStringValue(let v): return v
      }
    }

    /// Initialize from a string value.
    ///
    /// If the value is unknown, this initializes to [`unknownStringValue`](doc:KnownCertificateExtension/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "KNOWN_CERTIFICATE_EXTENSION_UNSPECIFIED": self = .unspecified
      case "BASE_KEY_USAGE": self = .baseKeyUsage
      case "EXTENDED_KEY_USAGE": self = .extendedKeyUsage
      case "CA_OPTIONS": self = .caOptions
      case "POLICY_IDS": self = .policyIds
      case "AIA_OCSP_SERVERS": self = .aiaOcspServers
      case "NAME_CONSTRAINTS": self = .nameConstraints
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:KnownCertificateExtension/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .baseKeyUsage
      case 2: self = .extendedKeyUsage
      case 3: self = .caOptions
      case 4: self = .policyIds
      case 5: self = .aiaOcspServers
      case 6: self = .nameConstraints
      default: self = .unknownIntValue(intValue)
      }
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.singleValueContainer()
      if let v = try? container.decode(Int.self) {
        self.init(intValue: v)
        return
      }
      if let s = try? container.decode(String.self) {
        if let v = Int(s) {
          self.init(intValue: v)
        } else {
          self.init(stringValue: s)
        }
        return
      }
      throw DecodingError.dataCorruptedError(
        in: container, debugDescription: "Expected enum value, must be integer or string.")
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.singleValueContainer()
      switch self {
      case .unspecified: return try container.encode(0)
      case .baseKeyUsage: return try container.encode(1)
      case .extendedKeyUsage: return try container.encode(2)
      case .caOptions: return try container.encode(3)
      case .policyIds: return try container.encode(4)
      case .aiaOcspServers: return try container.encode(5)
      case .nameConstraints: return try container.encode(6)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.cloud.security.privateca.v1.CertificateExtensionConstraints"
  }
  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)
  }
}
