// 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 representation of the Channel resource.
/// A Channel is a resource on which event providers publish their events.
/// The published events are delivered through the transport associated with the
/// channel. Note that a channel is associated with exactly one event provider.
public struct Channel: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. The resource name of the channel. Must be unique within the
  /// location on the project and must be in
  /// `projects/{project}/locations/{location}/channels/{channel_id}` format.
  public var name: Swift.String = Swift.String()

  /// Output only. Server assigned unique identifier for the channel. The value
  /// is a UUID4 string and guaranteed to remain unchanged until the resource is
  /// deleted.
  public var uid: Swift.String = Swift.String()

  /// Output only. The creation time.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The last-modified time.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// The name of the event provider (e.g. Eventarc SaaS partner) associated
  /// with the channel. This provider will be granted permissions to publish
  /// events to the channel. Format:
  /// `projects/{project}/locations/{location}/providers/{provider_id}`.
  public var provider: Swift.String = Swift.String()

  /// Output only. The state of a Channel.
  public var state: Channel.State = Channel.State()

  /// Output only. The activation token for the channel. The token must be used
  /// by the provider to register the channel for publishing.
  public var activationToken: Swift.String = Swift.String()

  /// Optional. Resource name of a KMS crypto key (managed by the user) used to
  /// encrypt/decrypt their event data.
  ///
  /// It must match the pattern
  /// `projects/*/locations/*/keyRings/*/cryptoKeys/*`.
  public var cryptoKeyName: Swift.String = Swift.String()

  /// Output only. Whether or not this Channel satisfies the requirements of
  /// physical zone separation
  public var satisfiesPzs: Swift.Bool = Swift.Bool()

  /// Optional. Resource labels.
  public var labels: [Swift.String: Swift.String] = [:]

  public var transport: OneOf_Transport? = nil

  /// Initialize a new instance of `Channel`.
  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 = Channel().with { $0.name = ... }
  /// ```
  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 name = "name"
    case uid = "uid"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case provider = "provider"
    case pubsubTopic = "pubsubTopic"
    case state = "state"
    case activationToken = "activationToken"
    case cryptoKeyName = "cryptoKeyName"
    case satisfiesPzs = "satisfiesPzs"
    case labels = "labels"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.uid = try container.decode(Swift.String.self, forKey: .uid)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.provider = try container.decode(Swift.String.self, forKey: .provider)
    self.state = try container.decode(Channel.State.self, forKey: .state)
    self.activationToken = try container.decode(Swift.String.self, forKey: .activationToken)
    self.cryptoKeyName = try container.decode(Swift.String.self, forKey: .cryptoKeyName)
    self.satisfiesPzs = try container.decode(Swift.Bool.self, forKey: .satisfiesPzs)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)

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

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.name, forKey: .name)
    try container.encode(self.uid, forKey: .uid)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.provider, forKey: .provider)
    try container.encode(self.state, forKey: .state)
    try container.encode(self.activationToken, forKey: .activationToken)
    try container.encode(self.cryptoKeyName, forKey: .cryptoKeyName)
    try container.encode(self.satisfiesPzs, forKey: .satisfiesPzs)
    try container.encode(self.labels, forKey: .labels)

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

  /// State lists all the possible states of a Channel
  public enum State: Codable, Equatable, Sendable {
    /// Default value. This value is unused.
    case unspecified
    /// The PENDING state indicates that a Channel has been created successfully
    /// and there is a new activation token available for the subscriber to use
    /// to convey the Channel to the provider in order to create a Connection.
    case pending
    /// The ACTIVE state indicates that a Channel has been successfully
    /// connected with the event provider.
    /// An ACTIVE Channel is ready to receive and route events from the
    /// event provider.
    case active
    /// The INACTIVE state indicates that the Channel cannot receive events
    /// permanently. There are two possible cases this state can happen:
    ///
    /// 1. The SaaS provider disconnected from this Channel.
    /// 2. The Channel activation token has expired but the SaaS provider
    ///    wasn't connected.
    ///
    /// To re-establish a Connection with a provider, the subscriber
    /// should create a new Channel and give it to the provider.
    case inactive
    /// 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 .pending: return 1
      case .active: return 2
      case .inactive: return 3
      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 "STATE_UNSPECIFIED"
      case .pending: return "PENDING"
      case .active: return "ACTIVE"
      case .inactive: return "INACTIVE"
      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:State/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "STATE_UNSPECIFIED": self = .unspecified
      case "PENDING": self = .pending
      case "ACTIVE": self = .active
      case "INACTIVE": self = .inactive
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .pending
      case 2: self = .active
      case 3: self = .inactive
      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 .pending: return try container.encode(1)
      case .active: return try container.encode(2)
      case .inactive: return try container.encode(3)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  public enum OneOf_Transport: Codable, Equatable, Sendable {
    /// Output only. The name of the Pub/Sub topic created and managed by
    /// Eventarc system as a transport for the event delivery. Format:
    /// `projects/{project}/topics/{topic_id}`.
    case pubsubTopic(Swift.String)
  }

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