// 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 DataFoundryService || EvaluationService || GenAiCacheService || GenAiTuningService || LlmUtilityService || PredictionService || SessionService || VertexRagService
  import Foundation
  import GoogleCloudWkt

  /// A datatype containing media that is part of a multi-part `Content` message.
  ///
  /// A `Part` consists of data which has an associated datatype. A `Part` can only
  /// contain one of the accepted types in `Part.data`.
  ///
  /// A `Part` must have a fixed IANA MIME type identifying the type and subtype
  /// of the media if `inline_data` or `file_data` field is filled with raw bytes.
  public struct Part: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Indicates if the part is thought from the model.
    public var thought: Swift.Bool = Swift.Bool()

    /// An opaque signature for the thought so it can be reused in subsequent
    /// requests.
    public var thoughtSignature: Foundation.Data = Foundation.Data()

    /// per part media resolution.
    /// Media resolution for the input media.
    public var mediaResolution: Part.MediaResolution? = nil

    public var data: OneOf_Data? = nil

    public var metadata: OneOf_Metadata? = nil

    /// Initialize a new instance of `Part`.
    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 = Part().with { $0.text = ... }
    /// ```
    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 text = "text"
      case inlineData = "inlineData"
      case fileData = "fileData"
      case functionCall = "functionCall"
      case functionResponse = "functionResponse"
      case executableCode = "executableCode"
      case codeExecutionResult = "codeExecutionResult"
      case thought = "thought"
      case thoughtSignature = "thoughtSignature"
      case videoMetadata = "videoMetadata"
      case mediaResolution = "mediaResolution"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.thought = try container.decode(Swift.Bool.self, forKey: .thought)
      self.thoughtSignature = try container.decode(Foundation.Data.self, forKey: .thoughtSignature)
      self.mediaResolution = try container.decodeIfPresent(
        Part.MediaResolution.self, forKey: .mediaResolution)

      var data: OneOf_Data? = nil
      let dataCheckAndSet = {
        if data != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'data'"))
        }
        data = $0
      }
      if let text = try container.decodeIfPresent(Swift.String.self, forKey: .text) {
        try dataCheckAndSet(.text(text))
      }
      if let inlineData = try container.decodeIfPresent(Blob?.self, forKey: .inlineData) {
        try dataCheckAndSet(.inlineData(inlineData))
      }
      if let fileData = try container.decodeIfPresent(FileData?.self, forKey: .fileData) {
        try dataCheckAndSet(.fileData(fileData))
      }
      if let functionCall = try container.decodeIfPresent(FunctionCall?.self, forKey: .functionCall)
      {
        try dataCheckAndSet(.functionCall(functionCall))
      }
      if let functionResponse = try container.decodeIfPresent(
        FunctionResponse?.self, forKey: .functionResponse)
      {
        try dataCheckAndSet(.functionResponse(functionResponse))
      }
      if let executableCode = try container.decodeIfPresent(
        ExecutableCode?.self, forKey: .executableCode)
      {
        try dataCheckAndSet(.executableCode(executableCode))
      }
      if let codeExecutionResult = try container.decodeIfPresent(
        CodeExecutionResult?.self, forKey: .codeExecutionResult)
      {
        try dataCheckAndSet(.codeExecutionResult(codeExecutionResult))
      }
      self.data = data

      var metadata: OneOf_Metadata? = nil
      let metadataCheckAndSet = {
        if metadata != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'metadata'"))
        }
        metadata = $0
      }
      if let videoMetadata = try container.decodeIfPresent(
        VideoMetadata?.self, forKey: .videoMetadata)
      {
        try metadataCheckAndSet(.videoMetadata(videoMetadata))
      }
      self.metadata = metadata
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.thought, forKey: .thought)
      try container.encode(self.thoughtSignature, forKey: .thoughtSignature)
      try container.encode(self.mediaResolution, forKey: .mediaResolution)

      if let choice = self.data {
        switch choice {
        case .text(let value):
          try container.encode(value, forKey: .text)
        case .inlineData(let value):
          try container.encode(value, forKey: .inlineData)
        case .fileData(let value):
          try container.encode(value, forKey: .fileData)
        case .functionCall(let value):
          try container.encode(value, forKey: .functionCall)
        case .functionResponse(let value):
          try container.encode(value, forKey: .functionResponse)
        case .executableCode(let value):
          try container.encode(value, forKey: .executableCode)
        case .codeExecutionResult(let value):
          try container.encode(value, forKey: .codeExecutionResult)
        }
      }

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

    /// per part media resolution.
    /// Media resolution for the input media.
    public struct MediaResolution: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      public var value: OneOf_Value? = nil

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

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

        var value: OneOf_Value? = nil
        let valueCheckAndSet = {
          if value != nil {
            throw DecodingError.dataCorrupted(
              DecodingError.Context(
                codingPath: decoder.codingPath,
                debugDescription: "Multiple values set for oneof 'value'"))
          }
          value = $0
        }
        if let level = try container.decodeIfPresent(
          Part.MediaResolution.Level.self, forKey: .level)
        {
          try valueCheckAndSet(.level(level))
        }
        self.value = value
      }

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

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

      /// The media resolution level.
      public enum Level: Codable, Equatable, Sendable {
        /// Media resolution has not been set.
        case mediaResolutionUnspecified
        /// Media resolution set to low.
        case mediaResolutionLow
        /// Media resolution set to medium.
        case mediaResolutionMedium
        /// Media resolution set to high.
        case mediaResolutionHigh
        /// Media resolution set to ultra high. This is for image only.
        case mediaResolutionUltraHigh
        /// 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 = .mediaResolutionUnspecified
        }

        /// 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 .mediaResolutionUnspecified: return 0
          case .mediaResolutionLow: return 1
          case .mediaResolutionMedium: return 2
          case .mediaResolutionHigh: return 3
          case .mediaResolutionUltraHigh: 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 .mediaResolutionUnspecified: return "MEDIA_RESOLUTION_UNSPECIFIED"
          case .mediaResolutionLow: return "MEDIA_RESOLUTION_LOW"
          case .mediaResolutionMedium: return "MEDIA_RESOLUTION_MEDIUM"
          case .mediaResolutionHigh: return "MEDIA_RESOLUTION_HIGH"
          case .mediaResolutionUltraHigh: return "MEDIA_RESOLUTION_ULTRA_HIGH"
          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:Level/unknownStringValue(_:)).
        public init(stringValue: Swift.String) {
          switch stringValue {
          case "MEDIA_RESOLUTION_UNSPECIFIED": self = .mediaResolutionUnspecified
          case "MEDIA_RESOLUTION_LOW": self = .mediaResolutionLow
          case "MEDIA_RESOLUTION_MEDIUM": self = .mediaResolutionMedium
          case "MEDIA_RESOLUTION_HIGH": self = .mediaResolutionHigh
          case "MEDIA_RESOLUTION_ULTRA_HIGH": self = .mediaResolutionUltraHigh
          default: self = .unknownStringValue(stringValue)
          }
        }

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

      public enum OneOf_Value: Codable, Equatable, Sendable {
        /// The tokenization quality used for given media.
        case level(Part.MediaResolution.Level)
      }

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

    public enum OneOf_Data: Codable, Equatable, Sendable {
      /// Optional. Text part (can be code).
      case text(Swift.String)
      /// Optional. Inlined bytes data.
      indirect case inlineData(Blob?)
      /// Optional. URI based data.
      indirect case fileData(FileData?)
      /// Optional. A predicted [FunctionCall] returned from the model that
      /// contains a string representing the [FunctionDeclaration.name] with the
      /// parameters and their values.
      indirect case functionCall(FunctionCall?)
      /// Optional. The result output of a [FunctionCall] that contains a string
      /// representing the [FunctionDeclaration.name] and a structured JSON object
      /// containing any output from the function call. It is used as context to
      /// the model.
      indirect case functionResponse(FunctionResponse?)
      /// Optional. Code generated by the model that is meant to be executed.
      indirect case executableCode(ExecutableCode?)
      /// Optional. Result of executing the [ExecutableCode].
      indirect case codeExecutionResult(CodeExecutionResult?)
    }

    public enum OneOf_Metadata: Codable, Equatable, Sendable {
      /// Optional. Video metadata. The metadata should only be specified while the
      /// video data is presented in inline_data or file_data.
      indirect case videoMetadata(VideoMetadata?)
    }

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