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

/// Configuration for a push delivery endpoint.
public struct PushConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. A URL locating the endpoint to which messages should be pushed.
  /// For example, a Webhook endpoint might use `https://example.com/push`.
  public var pushEndpoint: Swift.String = Swift.String()

  /// Optional. Endpoint configuration attributes that can be used to control
  /// different aspects of the message delivery.
  ///
  /// The only currently supported attribute is `x-goog-version`, which you can
  /// use to change the format of the pushed message. This attribute
  /// indicates the version of the data expected by the endpoint. This
  /// controls the shape of the pushed message (i.e., its fields and metadata).
  ///
  /// If not present during the `CreateSubscription` call, it will default to
  /// the version of the Pub/Sub API used to make such call. If not present in a
  /// `ModifyPushConfig` call, its value will not be changed. `GetSubscription`
  /// calls will always return a valid version, even if the subscription was
  /// created without this attribute.
  ///
  /// The only supported values for the `x-goog-version` attribute are:
  ///
  /// * `v1beta1`: uses the push format defined in the v1beta1 Pub/Sub API.
  /// * `v1` or `v1beta2`: uses the push format defined in the v1 Pub/Sub API.
  ///
  /// For example:
  /// `attributes { "x-goog-version": "v1" }`
  public var attributes: [Swift.String: Swift.String] = [:]

  /// An authentication method used by push endpoints to verify the source of
  /// push requests. This can be used with push endpoints that are private by
  /// default to allow requests only from the Pub/Sub system, for example.
  /// This field is optional and should be set only by users interested in
  /// authenticated push.
  public var authenticationMethod: OneOf_AuthenticationMethod? = nil

  /// The format of the delivered message to the push endpoint is defined by
  /// the chosen wrapper. When unset, `PubsubWrapper` is used.
  public var wrapper: OneOf_Wrapper? = nil

  /// Initialize a new instance of `PushConfig`.
  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 = PushConfig().with { $0.oidcToken = ... }
  /// ```
  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 oidcToken = "oidcToken"
    case pubsubWrapper = "pubsubWrapper"
    case noWrapper = "noWrapper"
    case pushEndpoint = "pushEndpoint"
    case attributes = "attributes"
  }

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

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

    var wrapper: OneOf_Wrapper? = nil
    let wrapperCheckAndSet = {
      if wrapper != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'wrapper'"))
      }
      wrapper = $0
    }
    if let pubsubWrapper = try container.decodeIfPresent(
      PushConfig.PubsubWrapper?.self, forKey: .pubsubWrapper)
    {
      try wrapperCheckAndSet(.pubsubWrapper(pubsubWrapper))
    }
    if let noWrapper = try container.decodeIfPresent(PushConfig.NoWrapper?.self, forKey: .noWrapper)
    {
      try wrapperCheckAndSet(.noWrapper(noWrapper))
    }
    self.wrapper = wrapper
  }

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

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

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

  /// Contains information needed for generating an
  /// [OpenID Connect
  /// token](https://developers.google.com/identity/protocols/OpenIDConnect).
  public struct OidcToken: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. [Service account
    /// email](https://cloud.google.com/iam/docs/service-accounts)
    /// used for generating the OIDC token. For more information
    /// on setting up authentication, see
    /// [Push subscriptions](https://cloud.google.com/pubsub/docs/push).
    public var serviceAccountEmail: Swift.String = Swift.String()

    /// Optional. Audience to be used when generating OIDC token. The audience
    /// claim identifies the recipients that the JWT is intended for. The
    /// audience value is a single case-sensitive string. Having multiple values
    /// (array) for the audience field is not supported. More info about the OIDC
    /// JWT token audience here:
    /// https://tools.ietf.org/html/rfc7519#section-4.1.3 Note: if not specified,
    /// the Push endpoint URL will be used.
    public var audience: Swift.String = Swift.String()

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

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

  /// The payload to the push endpoint is in the form of the JSON representation
  /// of a PubsubMessage
  /// (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage).
  public struct PubsubWrapper: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Initialize a new instance of `PubsubWrapper`.
    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 = PubsubWrapper().with { $0.<placeholder> = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

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

  /// Sets the `data` field as the HTTP body for delivery.
  public struct NoWrapper: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. When true, writes the Pub/Sub message metadata to
    /// `x-goog-pubsub-<KEY>:<VAL>` headers of the HTTP request. Writes the
    /// Pub/Sub message attributes to `<KEY>:<VAL>` headers of the HTTP request.
    public var writeMetadata: Swift.Bool = Swift.Bool()

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

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

  /// An authentication method used by push endpoints to verify the source of
  /// push requests. This can be used with push endpoints that are private by
  /// default to allow requests only from the Pub/Sub system, for example.
  /// This field is optional and should be set only by users interested in
  /// authenticated push.
  public enum OneOf_AuthenticationMethod: Codable, Equatable, Sendable {
    /// Optional. If specified, Pub/Sub will generate and attach an OIDC JWT
    /// token as an `Authorization` header in the HTTP request for every pushed
    /// message.
    indirect case oidcToken(PushConfig.OidcToken?)
  }

  /// The format of the delivered message to the push endpoint is defined by
  /// the chosen wrapper. When unset, `PubsubWrapper` is used.
  public enum OneOf_Wrapper: Codable, Equatable, Sendable {
    /// Optional. When set, the payload to the push endpoint is in the form of
    /// the JSON representation of a PubsubMessage
    /// (https://cloud.google.com/pubsub/docs/reference/rpc/google.pubsub.v1#pubsubmessage).
    indirect case pubsubWrapper(PushConfig.PubsubWrapper?)
    /// Optional. When set, the payload to the push endpoint is not wrapped.
    indirect case noWrapper(PushConfig.NoWrapper?)
  }

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