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

#if ReliabilityRisks
  import Foundation
  import GoogleCloudWkt

  /// Detailed insights and metrics about a detected reliability risk.
  public struct RiskDetails: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The duration of the risk since it was detected.
    public var duration: GoogleCloudWkt.Duration? = nil

    /// Insight details for global DNS risk.
    public var globalDnsInsight: RiskDetailsGlobalDnsInsight? = nil

    /// The last time the risk was updated.
    public var lastUpdateTimestamp: GoogleCloudWkt.Timestamp? = nil

    /// The severity of the risk.
    public var severity: RiskDetails.Severity? = nil

    /// The type of risk.
    public var type: RiskDetails.Type_? = nil

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

    /// The enumerated type for the [severity][google.cloud.compute.v1.RiskDetails.severity] field.
    ///
    /// [google.cloud.compute.v1.RiskDetails.severity]: <doc:RiskDetails/Severity>
    public enum Severity: Codable, Equatable, Sendable {
      /// Critical severity.
      case critical
      /// High severity.
      case high
      /// Low severity.
      case low
      /// Medium severity.
      case medium
      /// No severity specified. The default value.
      case unspecified
      /// 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 = .critical
      }

      /// 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 .critical: return 0
        case .high: return 1
        case .low: return 2
        case .medium: return 3
        case .unspecified: return 4
        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 .critical: return "CRITICAL"
        case .high: return "HIGH"
        case .low: return "LOW"
        case .medium: return "MEDIUM"
        case .unspecified: return "SEVERITY_UNSPECIFIED"
        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:Severity/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CRITICAL": self = .critical
        case "HIGH": self = .high
        case "LOW": self = .low
        case "MEDIUM": self = .medium
        case "SEVERITY_UNSPECIFIED": self = .unspecified
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// The enumerated type for the [type][google.cloud.compute.v1.RiskDetails.type] field.
    ///
    /// [google.cloud.compute.v1.RiskDetails.type]: <doc:RiskDetails/Type_>
    public enum Type_: Codable, Equatable, Sendable {
      /// Risk type related to global DNS.
      case globalDns
      /// Default value. This value is unused.
      case riskTypeUnspecified
      /// 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 = .globalDns
      }

      /// 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 .globalDns: return 0
        case .riskTypeUnspecified: return 1
        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 .globalDns: return "GLOBAL_DNS"
        case .riskTypeUnspecified: return "RISK_TYPE_UNSPECIFIED"
        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:Type_/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "GLOBAL_DNS": self = .globalDns
        case "RISK_TYPE_UNSPECIFIED": self = .riskTypeUnspecified
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:Type_/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .globalDns
        case 1: self = .riskTypeUnspecified
        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 .globalDns: return try container.encode(0)
        case .riskTypeUnspecified: return try container.encode(1)
        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.compute.v1.RiskDetails"
    }
    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)
    }
  }
#endif
