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

/// Settings for Binary Authorization feature.
public struct BinaryAuthorization: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. If present, indicates to use Breakglass using this justification.
  /// If use_default is False, then it must be empty.
  /// For more information on breakglass, see
  /// https://cloud.google.com/binary-authorization/docs/using-breakglass
  public var breakglassJustification: Swift.String = Swift.String()

  public var binauthzMethod: OneOf_BinauthzMethod? = nil

  /// Initialize a new instance of `BinaryAuthorization`.
  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 = BinaryAuthorization().with { $0.useDefault = ... }
  /// ```
  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 useDefault = "useDefault"
    case policy = "policy"
    case breakglassJustification = "breakglassJustification"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.breakglassJustification = try container.decode(
      Swift.String.self, forKey: .breakglassJustification)

    var binauthzMethod: OneOf_BinauthzMethod? = nil
    let binauthzMethodCheckAndSet = {
      if binauthzMethod != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'binauthzMethod'"))
      }
      binauthzMethod = $0
    }
    if let useDefault = try container.decodeIfPresent(Swift.Bool.self, forKey: .useDefault) {
      try binauthzMethodCheckAndSet(.useDefault(useDefault))
    }
    if let policy = try container.decodeIfPresent(Swift.String.self, forKey: .policy) {
      try binauthzMethodCheckAndSet(.policy(policy))
    }
    self.binauthzMethod = binauthzMethod
  }

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

    if let choice = self.binauthzMethod {
      switch choice {
      case .useDefault(let value):
        try container.encode(value, forKey: .useDefault)
      case .policy(let value):
        try container.encode(value, forKey: .policy)
      }
    }
  }

  public enum OneOf_BinauthzMethod: Codable, Equatable, Sendable {
    /// Optional. If True, indicates to use the default project's binary
    /// authorization policy. If False, binary authorization will be disabled.
    case useDefault(Swift.Bool)
    /// Optional. The path to a binary authorization policy.
    /// Format: `projects/{project}/platforms/cloudRun/{policy-name}`
    case policy(Swift.String)
  }

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