// 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 request message for language detection.
public struct DetectLanguageRequest: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Project or location to make a call. Must refer to a caller's
  /// project.
  ///
  /// Format: `projects/{project-number-or-id}/locations/{location-id}` or
  /// `projects/{project-number-or-id}`.
  ///
  /// For global calls, use `projects/{project-number-or-id}/locations/global` or
  /// `projects/{project-number-or-id}`.
  ///
  /// Only models within the same region (has same location-id) can be used.
  /// Otherwise an INVALID_ARGUMENT (400) error is returned.
  public var parent: Swift.String = Swift.String()

  /// Optional. The language detection model to be used.
  ///
  /// Format:
  /// `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/{model-id}`
  ///
  /// Only one language detection model is currently supported:
  /// `projects/{project-number-or-id}/locations/{location-id}/models/language-detection/default`.
  ///
  /// If not specified, the default model is used.
  public var model: Swift.String = Swift.String()

  /// Optional. The format of the source text, for example, "text/html",
  /// "text/plain". If left blank, the MIME type defaults to "text/html".
  public var mimeType: Swift.String = Swift.String()

  /// Optional. The labels with user-defined metadata for the request.
  ///
  /// Label keys and values can be no longer than 63 characters
  /// (Unicode codepoints), can only contain lowercase letters, numeric
  /// characters, underscores and dashes. International characters are allowed.
  /// Label values are optional. Label keys must start with a letter.
  ///
  /// See https://cloud.google.com/translate/docs/advanced/labels for more
  /// information.
  public var labels: [Swift.String: Swift.String] = [:]

  /// Required. The source of the document from which to detect the language.
  public var source: OneOf_Source? = nil

  /// Initialize a new instance of `DetectLanguageRequest`.
  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 = DetectLanguageRequest().with { $0.parent = ... }
  /// ```
  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 parent = "parent"
    case model = "model"
    case content = "content"
    case mimeType = "mimeType"
    case labels = "labels"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.parent = try container.decode(Swift.String.self, forKey: .parent)
    self.model = try container.decode(Swift.String.self, forKey: .model)
    self.mimeType = try container.decode(Swift.String.self, forKey: .mimeType)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)

    var source: OneOf_Source? = nil
    let sourceCheckAndSet = {
      if source != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'source'"))
      }
      source = $0
    }
    if let content = try container.decodeIfPresent(Swift.String.self, forKey: .content) {
      try sourceCheckAndSet(.content(content))
    }
    self.source = source
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.parent, forKey: .parent)
    try container.encode(self.model, forKey: .model)
    try container.encode(self.mimeType, forKey: .mimeType)
    try container.encode(self.labels, forKey: .labels)

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

  /// Required. The source of the document from which to detect the language.
  public enum OneOf_Source: Codable, Equatable, Sendable {
    /// The content of the input stored as a string.
    case content(Swift.String)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.cloud.translation.v3.DetectLanguageRequest"
  }
  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)
  }
}
