// 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

/// A policy that defines the replication and encryption configuration of data.
public struct Replication: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The replication policy for this secret.
  public var replication: OneOf_Replication? = nil

  /// Initialize a new instance of `Replication`.
  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 = Replication().with { $0.automatic = ... }
  /// ```
  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 automatic = "automatic"
    case userManaged = "userManaged"
  }

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

    var replication: OneOf_Replication? = nil
    let replicationCheckAndSet = {
      if replication != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'replication'"))
      }
      replication = $0
    }
    if let automatic = try container.decodeIfPresent(
      Replication.Automatic?.self, forKey: .automatic)
    {
      try replicationCheckAndSet(.automatic(automatic))
    }
    if let userManaged = try container.decodeIfPresent(
      Replication.UserManaged?.self, forKey: .userManaged)
    {
      try replicationCheckAndSet(.userManaged(userManaged))
    }
    self.replication = replication
  }

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

    if let choice = self.replication {
      switch choice {
      case .automatic(let value):
        try container.encode(value, forKey: .automatic)
      case .userManaged(let value):
        try container.encode(value, forKey: .userManaged)
      }
    }
  }

  /// A replication policy that replicates the
  /// [Secret][google.cloud.secretmanager.v1.Secret] payload without any
  /// restrictions.
  ///
  /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
  public struct Automatic: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The customer-managed encryption configuration of the
    /// [Secret][google.cloud.secretmanager.v1.Secret]. If no configuration is
    /// provided, Google-managed default encryption is used.
    ///
    /// Updates to the [Secret][google.cloud.secretmanager.v1.Secret] encryption
    /// configuration only apply to
    /// [SecretVersions][google.cloud.secretmanager.v1.SecretVersion] added
    /// afterwards. They do not apply retroactively to existing
    /// [SecretVersions][google.cloud.secretmanager.v1.SecretVersion].
    ///
    /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
    /// [google.cloud.secretmanager.v1.SecretVersion]: <doc:SecretVersion>
    public var customerManagedEncryption: CustomerManagedEncryption? = nil

    /// Initialize a new instance of `Automatic`.
    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 = Automatic().with { $0.customerManagedEncryption = ... }
    /// ```
    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.secretmanager.v1.Replication.Automatic"
    }
    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)
    }
  }

  /// A replication policy that replicates the
  /// [Secret][google.cloud.secretmanager.v1.Secret] payload into the locations
  /// specified in
  /// [Replication.UserManaged.replicas][google.cloud.secretmanager.v1.Replication.UserManaged.replicas]
  ///
  /// [google.cloud.secretmanager.v1.Replication.UserManaged.replicas]: <doc:Replication/UserManaged/replicas>
  /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
  public struct UserManaged: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The list of Replicas for this
    /// [Secret][google.cloud.secretmanager.v1.Secret].
    ///
    /// Cannot be empty.
    ///
    /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
    public var replicas: [Replication.UserManaged.Replica] = []

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

    /// Represents a Replica for this
    /// [Secret][google.cloud.secretmanager.v1.Secret].
    ///
    /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
    public struct Replica: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// The canonical IDs of the location to replicate data.
      /// For example: `"us-east1"`.
      public var location: Swift.String = Swift.String()

      /// Optional. The customer-managed encryption configuration of the
      /// [User-Managed Replica][Replication.UserManaged.Replica]. If no
      /// configuration is provided, Google-managed default encryption is used.
      ///
      /// Updates to the [Secret][google.cloud.secretmanager.v1.Secret]
      /// encryption configuration only apply to
      /// [SecretVersions][google.cloud.secretmanager.v1.SecretVersion] added
      /// afterwards. They do not apply retroactively to existing
      /// [SecretVersions][google.cloud.secretmanager.v1.SecretVersion].
      ///
      /// [Replication.UserManaged.Replica]: <doc:Replication/UserManaged/Replica>
      /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
      /// [google.cloud.secretmanager.v1.SecretVersion]: <doc:SecretVersion>
      public var customerManagedEncryption: CustomerManagedEncryption? = nil

      /// Initialize a new instance of `Replica`.
      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 = Replica().with { $0.location = ... }
      /// ```
      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.secretmanager.v1.Replication.UserManaged.Replica"
      }
      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 static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.secretmanager.v1.Replication.UserManaged"
    }
    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)
    }
  }

  /// The replication policy for this secret.
  public enum OneOf_Replication: Codable, Equatable, Sendable {
    /// The [Secret][google.cloud.secretmanager.v1.Secret] will automatically be
    /// replicated without any restrictions.
    ///
    /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
    indirect case automatic(Replication.Automatic?)
    /// The [Secret][google.cloud.secretmanager.v1.Secret] will only be
    /// replicated into the locations specified.
    ///
    /// [google.cloud.secretmanager.v1.Secret]: <doc:Secret>
    indirect case userManaged(Replication.UserManaged?)
  }

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