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

/// Http target. The job will be pushed to the job handler by means of
/// an HTTP request via an
/// [http_method][google.cloud.scheduler.v1.HttpTarget.http_method] such as HTTP
/// POST, HTTP GET, etc. The job is acknowledged by means of an HTTP
/// response code in the range [200 - 299]. A failure to receive a response
/// constitutes a failed execution. For a redirected request, the response
/// returned by the redirected request is considered.
///
/// [google.cloud.scheduler.v1.HttpTarget.http_method]: <doc:HttpTarget/httpMethod>
public struct HttpTarget: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. The full URI path that the request will be sent to. This string
  /// must begin with either "http://" or "https://". Some examples of
  /// valid values for [uri][google.cloud.scheduler.v1.HttpTarget.uri] are:
  /// `http://acme.com` and `https://acme.com/sales:8080`. Cloud Scheduler will
  /// encode some characters for safety and compatibility. The maximum allowed
  /// URL length is 2083 characters after encoding.
  ///
  /// [google.cloud.scheduler.v1.HttpTarget.uri]: <doc:HttpTarget/uri>
  public var uri: Swift.String = Swift.String()

  /// Which HTTP method to use for the request.
  public var httpMethod: HttpMethod = HttpMethod()

  /// HTTP request headers.
  ///
  /// This map contains the header field names and values.
  ///
  /// The user can specify HTTP request headers to send with the job's
  /// HTTP request. Repeated headers are not supported, but a header value can
  /// contain commas.
  ///
  /// The following headers represent a subset of the headers
  /// that accompany the job's HTTP request. Some HTTP request
  /// headers are ignored or replaced. A partial list of headers that
  /// are ignored or replaced is below:
  ///
  /// * Host: This will be computed by Cloud Scheduler and derived from
  /// [uri][google.cloud.scheduler.v1.HttpTarget.uri].
  /// * `Content-Length`: This will be computed by Cloud Scheduler.
  /// * `User-Agent`: This will be set to `"Google-Cloud-Scheduler"`.
  /// * `X-Google-*`: Google internal use only.
  /// * `X-AppEngine-*`: Google internal use only.
  /// * `X-CloudScheduler`: This header will be set to true.
  /// * `X-CloudScheduler-JobName`: This header will contain the job name.
  /// * `X-CloudScheduler-ScheduleTime`: For Cloud Scheduler jobs specified in
  /// the unix-cron format, this header will contain the job schedule as an
  /// offset of UTC parsed according to RFC3339.
  ///
  /// If the job has a [body][google.cloud.scheduler.v1.HttpTarget.body] and the
  /// following headers are not set by the user, Cloud Scheduler sets default
  /// values:
  ///
  /// * `Content-Type`: This will be set to `"application/octet-stream"`. You
  ///   can override this default by explicitly setting `Content-Type` to a
  ///   particular media type when creating the job. For example, you can set
  ///   `Content-Type` to `"application/json"`.
  ///
  /// The total size of headers must be less than 80KB.
  ///
  /// [google.cloud.scheduler.v1.HttpTarget.body]: <doc:HttpTarget/body>
  /// [google.cloud.scheduler.v1.HttpTarget.uri]: <doc:HttpTarget/uri>
  public var headers: [Swift.String: Swift.String] = [:]

  /// HTTP request body. A request body is allowed only if the HTTP
  /// method is POST, PUT, or PATCH. It is an error to set body on a job with an
  /// incompatible [HttpMethod][google.cloud.scheduler.v1.HttpMethod].
  ///
  /// [google.cloud.scheduler.v1.HttpMethod]: <doc:HttpMethod>
  public var body: Foundation.Data = Foundation.Data()

  /// The mode for generating an `Authorization` header for HTTP requests.
  ///
  /// If specified, all `Authorization` headers in the
  /// [HttpTarget.headers][google.cloud.scheduler.v1.HttpTarget.headers] field
  /// will be overridden.
  ///
  /// [google.cloud.scheduler.v1.HttpTarget.headers]: <doc:HttpTarget/headers>
  public var authorizationHeader: OneOf_AuthorizationHeader? = nil

  /// Initialize a new instance of `HttpTarget`.
  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 = HttpTarget().with { $0.uri = ... }
  /// ```
  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 uri = "uri"
    case httpMethod = "httpMethod"
    case headers = "headers"
    case body = "body"
    case oauthToken = "oauthToken"
    case oidcToken = "oidcToken"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.uri = try container.decode(Swift.String.self, forKey: .uri)
    self.httpMethod = try container.decode(HttpMethod.self, forKey: .httpMethod)
    self.headers = try container.decode([Swift.String: Swift.String].self, forKey: .headers)
    self.body = try container.decode(Foundation.Data.self, forKey: .body)

    var authorizationHeader: OneOf_AuthorizationHeader? = nil
    let authorizationHeaderCheckAndSet = {
      if authorizationHeader != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'authorizationHeader'"))
      }
      authorizationHeader = $0
    }
    if let oauthToken = try container.decodeIfPresent(OAuthToken?.self, forKey: .oauthToken) {
      try authorizationHeaderCheckAndSet(.oauthToken(oauthToken))
    }
    if let oidcToken = try container.decodeIfPresent(OidcToken?.self, forKey: .oidcToken) {
      try authorizationHeaderCheckAndSet(.oidcToken(oidcToken))
    }
    self.authorizationHeader = authorizationHeader
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.uri, forKey: .uri)
    try container.encode(self.httpMethod, forKey: .httpMethod)
    try container.encode(self.headers, forKey: .headers)
    try container.encode(self.body, forKey: .body)

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

  /// The mode for generating an `Authorization` header for HTTP requests.
  ///
  /// If specified, all `Authorization` headers in the
  /// [HttpTarget.headers][google.cloud.scheduler.v1.HttpTarget.headers] field
  /// will be overridden.
  ///
  /// [google.cloud.scheduler.v1.HttpTarget.headers]: <doc:HttpTarget/headers>
  public enum OneOf_AuthorizationHeader: Codable, Equatable, Sendable {
    /// If specified, an
    /// [OAuth token](https://developers.google.com/identity/protocols/OAuth2)
    /// will be generated and attached as an `Authorization` header in the HTTP
    /// request.
    ///
    /// This type of authorization should generally only be used when calling
    /// Google APIs hosted on *.googleapis.com.
    indirect case oauthToken(OAuthToken?)
    /// If specified, an
    /// [OIDC](https://developers.google.com/identity/protocols/OpenIDConnect)
    /// token will be generated and attached as an `Authorization` header in the
    /// HTTP request.
    ///
    /// This type of authorization can be used for many scenarios, including
    /// calling Cloud Run, or endpoints where you intend to validate the token
    /// yourself.
    indirect case oidcToken(OidcToken?)
  }

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