// 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 JobService
  import Foundation
  import GoogleCloudWkt

  /// The config for feature monitoring threshold.
  public struct ThresholdConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    public var threshold: OneOf_Threshold? = nil

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

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

      var threshold: OneOf_Threshold? = nil
      let thresholdCheckAndSet = {
        if threshold != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'threshold'"))
        }
        threshold = $0
      }
      if let value = try container.decodeIfPresent(Swift.Double.self, forKey: .value) {
        try thresholdCheckAndSet(.value(value))
      }
      self.threshold = threshold
    }

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

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

    public enum OneOf_Threshold: Codable, Equatable, Sendable {
      /// Specify a threshold value that can trigger the alert.
      /// If this threshold config is for feature distribution distance:
      ///   1. For categorical feature, the distribution distance is calculated by
      ///      L-inifinity norm.
      ///   2. For numerical feature, the distribution distance is calculated by
      ///      Jensen–Shannon divergence.
      /// Each feature must have a non-zero threshold if they need to be monitored.
      /// Otherwise no alert will be triggered for that feature.
      case value(Swift.Double)
    }

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