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

/// A Dataproc job for running [Apache Pig](https://pig.apache.org/)
/// queries on YARN.
public struct PigJob: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. Whether to continue executing queries if a query fails.
  /// The default value is `false`. Setting to `true` can be useful when
  /// executing independent parallel queries.
  public var continueOnFailure: Swift.Bool = Swift.Bool()

  /// Optional. Mapping of query variable names to values (equivalent to the Pig
  /// command: `name=[value]`).
  public var scriptVariables: [Swift.String: Swift.String] = [:]

  /// Optional. A mapping of property names to values, used to configure Pig.
  /// Properties that conflict with values set by the Dataproc API might be
  /// overwritten. Can include properties set in `/etc/hadoop/conf/*-site.xml`,
  /// /etc/pig/conf/pig.properties, and classes in user code.
  public var properties: [Swift.String: Swift.String] = [:]

  /// Optional. HCFS URIs of jar files to add to the CLASSPATH of
  /// the Pig Client and Hadoop MapReduce (MR) tasks. Can contain Pig UDFs.
  public var jarFileUris: [Swift.String] = []

  /// Optional. The runtime log config for job execution.
  public var loggingConfig: LoggingConfig? = nil

  /// Required. The sequence of Pig queries to execute, specified as an HCFS
  /// file URI or a list of queries.
  public var queries: OneOf_Queries? = nil

  /// Initialize a new instance of `PigJob`.
  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 = PigJob().with { $0.queryFileUri = ... }
  /// ```
  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 queryFileUri = "queryFileUri"
    case queryList = "queryList"
    case continueOnFailure = "continueOnFailure"
    case scriptVariables = "scriptVariables"
    case properties = "properties"
    case jarFileUris = "jarFileUris"
    case loggingConfig = "loggingConfig"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.continueOnFailure = try container.decode(Swift.Bool.self, forKey: .continueOnFailure)
    self.scriptVariables = try container.decode(
      [Swift.String: Swift.String].self, forKey: .scriptVariables)
    self.properties = try container.decode([Swift.String: Swift.String].self, forKey: .properties)
    self.jarFileUris = try container.decode([Swift.String].self, forKey: .jarFileUris)
    self.loggingConfig = try container.decodeIfPresent(LoggingConfig.self, forKey: .loggingConfig)

    var queries: OneOf_Queries? = nil
    let queriesCheckAndSet = {
      if queries != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'queries'"))
      }
      queries = $0
    }
    if let queryFileUri = try container.decodeIfPresent(Swift.String.self, forKey: .queryFileUri) {
      try queriesCheckAndSet(.queryFileUri(queryFileUri))
    }
    if let queryList = try container.decodeIfPresent(QueryList?.self, forKey: .queryList) {
      try queriesCheckAndSet(.queryList(queryList))
    }
    self.queries = queries
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.continueOnFailure, forKey: .continueOnFailure)
    try container.encode(self.scriptVariables, forKey: .scriptVariables)
    try container.encode(self.properties, forKey: .properties)
    try container.encode(self.jarFileUris, forKey: .jarFileUris)
    try container.encode(self.loggingConfig, forKey: .loggingConfig)

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

  /// Required. The sequence of Pig queries to execute, specified as an HCFS
  /// file URI or a list of queries.
  public enum OneOf_Queries: Codable, Equatable, Sendable {
    /// The HCFS URI of the script that contains the Pig queries.
    case queryFileUri(Swift.String)
    /// A list of queries.
    indirect case queryList(QueryList?)
  }

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