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

import Foundation
import GoogleCloudWkt

/// The type of Google Cloud Vision API detection to perform, and the maximum
/// number of results to return for that type. Multiple `Feature` objects can
/// be specified in the `features` list.
public struct Feature: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The feature type.
  public var type: Feature.Type_ = Feature.Type_()

  /// Maximum number of results of this type. Does not apply to
  /// `TEXT_DETECTION`, `DOCUMENT_TEXT_DETECTION`, or `CROP_HINTS`.
  public var maxResults: Swift.Int32 = Swift.Int32()

  /// Model to use for the feature.
  /// Supported values: "builtin/stable" (the default if unset) and
  /// "builtin/latest". `DOCUMENT_TEXT_DETECTION` and `TEXT_DETECTION` also
  /// support "builtin/weekly" for the bleeding edge release updated weekly.
  public var model: Swift.String = Swift.String()

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

  /// Type of Google Cloud Vision API feature to be extracted.
  public enum Type_: Codable, Equatable, Sendable {
    /// Unspecified feature type.
    case unspecified
    /// Run face detection.
    case faceDetection
    /// Run landmark detection.
    case landmarkDetection
    /// Run logo detection.
    case logoDetection
    /// Run label detection.
    case labelDetection
    /// Run text detection / optical character recognition (OCR). Text detection
    /// is optimized for areas of text within a larger image; if the image is
    /// a document, use `DOCUMENT_TEXT_DETECTION` instead.
    case textDetection
    /// Run Safe Search to detect potentially unsafe
    /// or undesirable content.
    case safeSearchDetection
    /// Compute a set of image properties, such as the
    /// image's dominant colors.
    case imageProperties
    /// Run crop hints.
    case cropHints
    /// Run web detection.
    case webDetection
    /// Run dense text document OCR. Takes precedence when both
    /// `DOCUMENT_TEXT_DETECTION` and `TEXT_DETECTION` are present.
    case documentTextDetection
    /// Run Product Search.
    case productSearch
    /// Run localizer for object detection.
    case objectLocalization
    /// 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 .faceDetection: return 1
      case .landmarkDetection: return 2
      case .logoDetection: return 3
      case .labelDetection: return 4
      case .textDetection: return 5
      case .safeSearchDetection: return 6
      case .imageProperties: return 7
      case .cropHints: return 9
      case .webDetection: return 10
      case .documentTextDetection: return 11
      case .productSearch: return 12
      case .objectLocalization: return 19
      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 "TYPE_UNSPECIFIED"
      case .faceDetection: return "FACE_DETECTION"
      case .landmarkDetection: return "LANDMARK_DETECTION"
      case .logoDetection: return "LOGO_DETECTION"
      case .labelDetection: return "LABEL_DETECTION"
      case .textDetection: return "TEXT_DETECTION"
      case .safeSearchDetection: return "SAFE_SEARCH_DETECTION"
      case .imageProperties: return "IMAGE_PROPERTIES"
      case .cropHints: return "CROP_HINTS"
      case .webDetection: return "WEB_DETECTION"
      case .documentTextDetection: return "DOCUMENT_TEXT_DETECTION"
      case .productSearch: return "PRODUCT_SEARCH"
      case .objectLocalization: return "OBJECT_LOCALIZATION"
      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 "TYPE_UNSPECIFIED": self = .unspecified
      case "FACE_DETECTION": self = .faceDetection
      case "LANDMARK_DETECTION": self = .landmarkDetection
      case "LOGO_DETECTION": self = .logoDetection
      case "LABEL_DETECTION": self = .labelDetection
      case "TEXT_DETECTION": self = .textDetection
      case "DOCUMENT_TEXT_DETECTION": self = .documentTextDetection
      case "SAFE_SEARCH_DETECTION": self = .safeSearchDetection
      case "IMAGE_PROPERTIES": self = .imageProperties
      case "CROP_HINTS": self = .cropHints
      case "WEB_DETECTION": self = .webDetection
      case "PRODUCT_SEARCH": self = .productSearch
      case "OBJECT_LOCALIZATION": self = .objectLocalization
      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 = .unspecified
      case 1: self = .faceDetection
      case 2: self = .landmarkDetection
      case 3: self = .logoDetection
      case 4: self = .labelDetection
      case 5: self = .textDetection
      case 6: self = .safeSearchDetection
      case 7: self = .imageProperties
      case 9: self = .cropHints
      case 10: self = .webDetection
      case 11: self = .documentTextDetection
      case 12: self = .productSearch
      case 19: self = .objectLocalization
      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 .faceDetection: return try container.encode(1)
      case .landmarkDetection: return try container.encode(2)
      case .logoDetection: return try container.encode(3)
      case .labelDetection: return try container.encode(4)
      case .textDetection: return try container.encode(5)
      case .safeSearchDetection: return try container.encode(6)
      case .imageProperties: return try container.encode(7)
      case .cropHints: return try container.encode(9)
      case .webDetection: return try container.encode(10)
      case .documentTextDetection: return try container.encode(11)
      case .productSearch: return try container.encode(12)
      case .objectLocalization: return try container.encode(19)
      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.vision.v1.Feature"
  }
  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)
  }
}
