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

/// Describes EventTrigger, used to request events to be sent from another
/// service.
public struct EventTrigger: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The resource name of the Eventarc trigger. The format of this
  /// field is `projects/{project}/locations/{region}/triggers/{trigger}`.
  public var trigger: Swift.String = Swift.String()

  /// The region that the trigger will be in. The trigger will only receive
  /// events originating in this region. It can be the same
  /// region as the function, a different region or multi-region, or the global
  /// region. If not provided, defaults to the same region as the function.
  public var triggerRegion: Swift.String = Swift.String()

  /// Required. The type of event to observe. For example:
  /// `google.cloud.audit.log.v1.written` or
  /// `google.cloud.pubsub.topic.v1.messagePublished`.
  public var eventType: Swift.String = Swift.String()

  /// Criteria used to filter events.
  public var eventFilters: [EventFilter] = []

  /// Optional. The name of a Pub/Sub topic in the same project that will be used
  /// as the transport topic for the event delivery. Format:
  /// `projects/{project}/topics/{topic}`.
  ///
  /// This is only valid for events of type
  /// `google.cloud.pubsub.topic.v1.messagePublished`. The topic provided here
  /// will not be deleted at function deletion.
  public var pubsubTopic: Swift.String = Swift.String()

  /// Optional. The email of the trigger's service account. The service account
  /// must have permission to invoke Cloud Run services, the permission is
  /// `run.routes.invoke`.
  /// If empty, defaults to the Compute Engine default service account:
  /// `{project_number}-compute@developer.gserviceaccount.com`.
  public var serviceAccountEmail: Swift.String = Swift.String()

  /// Optional. If unset, then defaults to ignoring failures (i.e. not retrying
  /// them).
  public var retryPolicy: EventTrigger.RetryPolicy = EventTrigger.RetryPolicy()

  /// Optional. The name of the channel associated with the trigger in
  /// `projects/{project}/locations/{location}/channels/{channel}` format.
  /// You must provide a channel to receive events from Eventarc SaaS partners.
  public var channel: Swift.String = Swift.String()

  /// Optional. The hostname of the service that 1st Gen function should be
  /// observed.
  ///
  /// If no string is provided, the default service implementing the API will
  /// be used. For example, `storage.googleapis.com` is the default for all
  /// event types in the `google.storage` namespace.
  ///
  /// The field is only applicable to 1st Gen functions.
  public var service: Swift.String = Swift.String()

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

  /// Describes the retry policy in case of function's execution failure.
  /// Retried execution is charged as any other execution.
  public enum RetryPolicy: Codable, Equatable, Sendable {
    /// Not specified.
    case unspecified
    /// Do not retry.
    case doNotRetry
    /// Retry on any failure, retry up to 7 days with an exponential backoff
    /// (capped at 10 seconds).
    case retry
    /// 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 .doNotRetry: return 1
      case .retry: return 2
      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 "RETRY_POLICY_UNSPECIFIED"
      case .doNotRetry: return "RETRY_POLICY_DO_NOT_RETRY"
      case .retry: return "RETRY_POLICY_RETRY"
      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:RetryPolicy/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "RETRY_POLICY_UNSPECIFIED": self = .unspecified
      case "RETRY_POLICY_DO_NOT_RETRY": self = .doNotRetry
      case "RETRY_POLICY_RETRY": self = .retry
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:RetryPolicy/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .doNotRetry
      case 2: self = .retry
      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 .doNotRetry: return try container.encode(1)
      case .retry: return try container.encode(2)
      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.functions.v2.EventTrigger"
  }
  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)
  }
}
