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

/// Payload proto for "clouddeploy.googleapis.com/deploypolicy_evaluation"
/// Platform Log event that describes the deploy policy evaluation event.
public struct DeployPolicyEvaluationEvent: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Debug message for when a deploy policy event occurs.
  public var message: Swift.String = Swift.String()

  /// Rule type (e.g. Restrict Rollouts).
  public var ruleType: Swift.String = Swift.String()

  /// Rule id.
  public var rule: Swift.String = Swift.String()

  /// Unique identifier of the `Delivery Pipeline`.
  public var pipelineUid: Swift.String = Swift.String()

  /// The name of the `Delivery Pipeline`.
  public var deliveryPipeline: Swift.String = Swift.String()

  /// Unique identifier of the `Target`. This is an optional field, as a `Target`
  /// may not always be applicable to a policy.
  public var targetUid: Swift.String = Swift.String()

  /// The name of the `Target`. This is an optional field, as a `Target` may not
  /// always be applicable to a policy.
  public var target: Swift.String = Swift.String()

  /// What invoked the action (e.g. a user or automation).
  public var invoker: DeployPolicy.Invoker = DeployPolicy.Invoker()

  /// The name of the `DeployPolicy`.
  public var deployPolicy: Swift.String = Swift.String()

  /// Unique identifier of the `DeployPolicy`.
  public var deployPolicyUid: Swift.String = Swift.String()

  /// Whether the request is allowed. Allowed is set as true if:
  /// (1) the request complies with the policy; or
  /// (2) the request doesn't comply with the policy but the policy was
  /// overridden; or
  /// (3) the request doesn't comply with the policy but the policy was suspended
  public var allowed: Swift.Bool = Swift.Bool()

  /// The policy verdict of the request.
  public var verdict: DeployPolicyEvaluationEvent.PolicyVerdict =
    DeployPolicyEvaluationEvent.PolicyVerdict()

  /// Things that could have overridden the policy verdict. Overrides together
  /// with verdict decide whether the request is allowed.
  public var overrides: [DeployPolicyEvaluationEvent.PolicyVerdictOverride] = []

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

  /// The policy verdict of the request.
  public enum PolicyVerdict: Codable, Equatable, Sendable {
    /// This should never happen.
    case unspecified
    /// Allowed by policy. This enum value is not currently used but may be used
    /// in the future. Currently logs are only generated when a request is denied
    /// by policy.
    case allowedByPolicy
    /// Denied by policy.
    case deniedByPolicy
    /// 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 .allowedByPolicy: return 1
      case .deniedByPolicy: return 2
      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 "POLICY_VERDICT_UNSPECIFIED"
      case .allowedByPolicy: return "ALLOWED_BY_POLICY"
      case .deniedByPolicy: return "DENIED_BY_POLICY"
      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:PolicyVerdict/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "POLICY_VERDICT_UNSPECIFIED": self = .unspecified
      case "ALLOWED_BY_POLICY": self = .allowedByPolicy
      case "DENIED_BY_POLICY": self = .deniedByPolicy
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:PolicyVerdict/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .allowedByPolicy
      case 2: self = .deniedByPolicy
      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 .allowedByPolicy: return try container.encode(1)
      case .deniedByPolicy: return try container.encode(2)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// Things that could have overridden the policy verdict. When overrides are
  /// used, the request will be allowed even if it is DENIED_BY_POLICY.
  public enum PolicyVerdictOverride: Codable, Equatable, Sendable {
    /// This should never happen.
    case unspecified
    /// The policy was overridden.
    case policyOverridden
    /// The policy was suspended.
    case policySuspended
    /// 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 .policyOverridden: return 1
      case .policySuspended: return 2
      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 "POLICY_VERDICT_OVERRIDE_UNSPECIFIED"
      case .policyOverridden: return "POLICY_OVERRIDDEN"
      case .policySuspended: return "POLICY_SUSPENDED"
      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:PolicyVerdictOverride/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "POLICY_VERDICT_OVERRIDE_UNSPECIFIED": self = .unspecified
      case "POLICY_OVERRIDDEN": self = .policyOverridden
      case "POLICY_SUSPENDED": self = .policySuspended
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:PolicyVerdictOverride/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .policyOverridden
      case 2: self = .policySuspended
      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 .policyOverridden: return try container.encode(1)
      case .policySuspended: return try container.encode(2)
      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.deploy.v1.DeployPolicyEvaluationEvent"
  }
  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)
  }
}
