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

  /// Explanation of a prediction (provided in
  /// [PredictResponse.predictions][google.cloud.aiplatform.v1.PredictResponse.predictions])
  /// produced by the Model on a given
  /// [instance][google.cloud.aiplatform.v1.ExplainRequest.instances].
  ///
  /// [google.cloud.aiplatform.v1.ExplainRequest.instances]: <doc:ExplainRequest/instances>
  /// [google.cloud.aiplatform.v1.PredictResponse.predictions]: <doc:PredictResponse/predictions>
  public struct Explanation: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. Feature attributions grouped by predicted outputs.
    ///
    /// For Models that predict only one output, such as regression Models that
    /// predict only one score, there is only one attibution that explains the
    /// predicted output. For Models that predict multiple outputs, such as
    /// multiclass Models that predict multiple classes, each element explains one
    /// specific item.
    /// [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index]
    /// can be used to identify which output this attribution is explaining.
    ///
    /// By default, we provide Shapley values for the predicted class. However,
    /// you can configure the explanation request to generate Shapley values for
    /// any other classes too. For example, if a model predicts a probability of
    /// `0.4` for approving a loan application, the model's decision is to reject
    /// the application since `p(reject) = 0.6 > p(approve) = 0.4`, and the default
    /// Shapley values would be computed for rejection decision and not approval,
    /// even though the latter might be the positive class.
    ///
    /// If users set
    /// [ExplanationParameters.top_k][google.cloud.aiplatform.v1.ExplanationParameters.top_k],
    /// the attributions are sorted by
    /// [instance_output_value][google.cloud.aiplatform.v1.Attribution.instance_output_value]
    /// in descending order. If
    /// [ExplanationParameters.output_indices][google.cloud.aiplatform.v1.ExplanationParameters.output_indices]
    /// is specified, the attributions are stored by
    /// [Attribution.output_index][google.cloud.aiplatform.v1.Attribution.output_index]
    /// in the same order as they appear in the output_indices.
    ///
    /// [google.cloud.aiplatform.v1.Attribution.instance_output_value]: <doc:Attribution/instanceOutputValue>
    /// [google.cloud.aiplatform.v1.Attribution.output_index]: <doc:Attribution/outputIndex>
    /// [google.cloud.aiplatform.v1.ExplanationParameters.output_indices]: <doc:ExplanationParameters/outputIndices>
    /// [google.cloud.aiplatform.v1.ExplanationParameters.top_k]: <doc:ExplanationParameters/topK>
    public var attributions: [Attribution] = []

    /// Output only. List of the nearest neighbors for example-based explanations.
    ///
    /// For models deployed with the examples explanations feature enabled, the
    /// attributions field is empty and instead the neighbors field is populated.
    public var neighbors: [Neighbor] = []

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