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

  /// A message representing a Trial. A Trial contains a unique set of Parameters
  /// that has been or will be evaluated, along with the objective metrics got by
  /// running the Trial.
  public struct Trial: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. Resource name of the Trial assigned by the service.
    public var name: Swift.String = Swift.String()

    /// Output only. The identifier of the Trial assigned by the service.
    public var id: Swift.String = Swift.String()

    /// Output only. The detailed state of the Trial.
    public var state: Trial.State = Trial.State()

    /// Output only. The parameters of the Trial.
    public var parameters: [Trial.Parameter] = []

    /// Output only. The final measurement containing the objective value.
    public var finalMeasurement: Measurement? = nil

    /// Output only. A list of measurements that are strictly lexicographically
    /// ordered by their induced tuples (steps, elapsed_duration).
    /// These are used for early stopping computations.
    public var measurements: [Measurement] = []

    /// Output only. Time when the Trial was started.
    public var startTime: GoogleCloudWkt.Timestamp? = nil

    /// Output only. Time when the Trial's status changed to `SUCCEEDED` or
    /// `INFEASIBLE`.
    public var endTime: GoogleCloudWkt.Timestamp? = nil

    /// Output only. The identifier of the client that originally requested this
    /// Trial. Each client is identified by a unique client_id. When a client asks
    /// for a suggestion, Vertex AI Vizier will assign it a Trial. The client
    /// should evaluate the Trial, complete it, and report back to Vertex AI
    /// Vizier. If suggestion is asked again by same client_id before the Trial is
    /// completed, the same Trial will be returned. Multiple clients with
    /// different client_ids can ask for suggestions simultaneously, each of them
    /// will get their own Trial.
    public var clientId: Swift.String = Swift.String()

    /// Output only. A human readable string describing why the Trial is
    /// infeasible. This is set only if Trial state is `INFEASIBLE`.
    public var infeasibleReason: Swift.String = Swift.String()

    /// Output only. The CustomJob name linked to the Trial.
    /// It's set for a HyperparameterTuningJob's Trial.
    public var customJob: Swift.String = Swift.String()

    /// Output only. URIs for accessing [interactive
    /// shells](https://cloud.google.com/vertex-ai/docs/training/monitor-debug-interactive-shell)
    /// (one URI for each training node). Only available if this trial is part of
    /// a
    /// [HyperparameterTuningJob][google.cloud.aiplatform.v1.HyperparameterTuningJob]
    /// and the job's
    /// [trial_job_spec.enable_web_access][google.cloud.aiplatform.v1.CustomJobSpec.enable_web_access]
    /// field is `true`.
    ///
    /// The keys are names of each node used for the trial; for example,
    /// `workerpool0-0` for the primary node, `workerpool1-0` for the first node in
    /// the second worker pool, and `workerpool1-1` for the second node in the
    /// second worker pool.
    ///
    /// The values are the URIs for each node's interactive shell.
    ///
    /// [google.cloud.aiplatform.v1.CustomJobSpec.enable_web_access]: <doc:CustomJobSpec/enableWebAccess>
    /// [google.cloud.aiplatform.v1.HyperparameterTuningJob]: <doc:HyperparameterTuningJob>
    public var webAccessUris: [Swift.String: Swift.String] = [:]

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

    /// A message representing a parameter to be tuned.
    public struct Parameter: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Output only. The ID of the parameter. The parameter should be defined in
      /// [StudySpec's
      /// Parameters][google.cloud.aiplatform.v1.StudySpec.parameters].
      ///
      /// [google.cloud.aiplatform.v1.StudySpec.parameters]: <doc:StudySpec/parameters>
      public var parameterId: Swift.String = Swift.String()

      /// Output only. The value of the parameter.
      /// `number_value` will be set if a parameter defined in StudySpec is
      /// in type 'INTEGER', 'DOUBLE' or 'DISCRETE'.
      /// `string_value` will be set if a parameter defined in StudySpec is
      /// in type 'CATEGORICAL'.
      public var value: GoogleCloudWkt.Value? = nil

      /// Initialize a new instance of `Parameter`.
      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 = Parameter().with { $0.parameterId = ... }
      /// ```
      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.aiplatform.v1.Trial.Parameter"
      }
      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)
      }
    }

    /// Describes a Trial state.
    public enum State: Codable, Equatable, Sendable {
      /// The Trial state is unspecified.
      case unspecified
      /// Indicates that a specific Trial has been requested, but it has not yet
      /// been suggested by the service.
      case requested
      /// Indicates that the Trial has been suggested.
      case active
      /// Indicates that the Trial should stop according to the service.
      case stopping
      /// Indicates that the Trial is completed successfully.
      case succeeded
      /// Indicates that the Trial should not be attempted again.
      /// The service will set a Trial to INFEASIBLE when it's done but missing
      /// the final_measurement.
      case infeasible
      /// 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 .requested: return 1
        case .active: return 2
        case .stopping: return 3
        case .succeeded: return 4
        case .infeasible: return 5
        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 "STATE_UNSPECIFIED"
        case .requested: return "REQUESTED"
        case .active: return "ACTIVE"
        case .stopping: return "STOPPING"
        case .succeeded: return "SUCCEEDED"
        case .infeasible: return "INFEASIBLE"
        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:State/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "STATE_UNSPECIFIED": self = .unspecified
        case "REQUESTED": self = .requested
        case "ACTIVE": self = .active
        case "STOPPING": self = .stopping
        case "SUCCEEDED": self = .succeeded
        case "INFEASIBLE": self = .infeasible
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .requested
        case 2: self = .active
        case 3: self = .stopping
        case 4: self = .succeeded
        case 5: self = .infeasible
        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 .requested: return try container.encode(1)
        case .active: return try container.encode(2)
        case .stopping: return try container.encode(3)
        case .succeeded: return try container.encode(4)
        case .infeasible: return try container.encode(5)
        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.aiplatform.v1.Trial"
    }
    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
