// 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 resource representing streaming data from a source to a destination.
public struct Stream: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. Identifier. The stream's name.
  public var name: Swift.String = Swift.String()

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

  /// Output only. The last update time of the stream.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Labels.
  public var labels: [Swift.String: Swift.String] = [:]

  /// Required. Display name.
  public var displayName: Swift.String = Swift.String()

  /// Required. Source connection profile configuration.
  public var sourceConfig: SourceConfig? = nil

  /// Required. Destination connection profile configuration.
  public var destinationConfig: DestinationConfig? = nil

  /// The state of the stream.
  public var state: Stream.State = Stream.State()

  /// Output only. Errors on the Stream.
  public var errors: [Error] = []

  /// Immutable. A reference to a KMS encryption key.
  /// If provided, it will be used to encrypt the data.
  /// If left blank, data will be encrypted using an internal Stream-specific
  /// encryption key provisioned through KMS.
  public var customerManagedEncryptionKey: Swift.String? = nil

  /// Output only. If the stream was recovered, the time of the last recovery.
  /// Note: This field is currently experimental.
  public var lastRecoveryTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Reserved for future use.
  public var satisfiesPzs: Swift.Bool? = nil

  /// Output only. Reserved for future use.
  public var satisfiesPzi: Swift.Bool? = nil

  /// Stream backfill strategy.
  public var backfillStrategy: OneOf_BackfillStrategy? = nil

  /// Initialize a new instance of `Stream`.
  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 = Stream().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 createTime = "createTime"
    case updateTime = "updateTime"
    case labels = "labels"
    case displayName = "displayName"
    case sourceConfig = "sourceConfig"
    case destinationConfig = "destinationConfig"
    case state = "state"
    case backfillAll = "backfillAll"
    case backfillNone = "backfillNone"
    case errors = "errors"
    case customerManagedEncryptionKey = "customerManagedEncryptionKey"
    case lastRecoveryTime = "lastRecoveryTime"
    case satisfiesPzs = "satisfiesPzs"
    case satisfiesPzi = "satisfiesPzi"
  }

  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.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)
    self.displayName = try container.decode(Swift.String.self, forKey: .displayName)
    self.sourceConfig = try container.decodeIfPresent(SourceConfig.self, forKey: .sourceConfig)
    self.destinationConfig = try container.decodeIfPresent(
      DestinationConfig.self, forKey: .destinationConfig)
    self.state = try container.decode(Stream.State.self, forKey: .state)
    self.errors = try container.decode([Error].self, forKey: .errors)
    self.customerManagedEncryptionKey = try container.decodeIfPresent(
      Swift.String.self, forKey: .customerManagedEncryptionKey)
    self.lastRecoveryTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .lastRecoveryTime)
    self.satisfiesPzs = try container.decodeIfPresent(Swift.Bool.self, forKey: .satisfiesPzs)
    self.satisfiesPzi = try container.decodeIfPresent(Swift.Bool.self, forKey: .satisfiesPzi)

    var backfillStrategy: OneOf_BackfillStrategy? = nil
    let backfillStrategyCheckAndSet = {
      if backfillStrategy != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'backfillStrategy'"))
      }
      backfillStrategy = $0
    }
    if let backfillAll = try container.decodeIfPresent(
      Stream.BackfillAllStrategy?.self, forKey: .backfillAll)
    {
      try backfillStrategyCheckAndSet(.backfillAll(backfillAll))
    }
    if let backfillNone = try container.decodeIfPresent(
      Stream.BackfillNoneStrategy?.self, forKey: .backfillNone)
    {
      try backfillStrategyCheckAndSet(.backfillNone(backfillNone))
    }
    self.backfillStrategy = backfillStrategy
  }

  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.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.labels, forKey: .labels)
    try container.encode(self.displayName, forKey: .displayName)
    try container.encode(self.sourceConfig, forKey: .sourceConfig)
    try container.encode(self.destinationConfig, forKey: .destinationConfig)
    try container.encode(self.state, forKey: .state)
    try container.encode(self.errors, forKey: .errors)
    try container.encode(self.customerManagedEncryptionKey, forKey: .customerManagedEncryptionKey)
    try container.encode(self.lastRecoveryTime, forKey: .lastRecoveryTime)
    try container.encode(self.satisfiesPzs, forKey: .satisfiesPzs)
    try container.encode(self.satisfiesPzi, forKey: .satisfiesPzi)

    if let choice = self.backfillStrategy {
      switch choice {
      case .backfillAll(let value):
        try container.encode(value, forKey: .backfillAll)
      case .backfillNone(let value):
        try container.encode(value, forKey: .backfillNone)
      }
    }
  }

  /// Backfill strategy to automatically backfill the Stream's objects.
  /// Specific objects can be excluded.
  public struct BackfillAllStrategy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// List of objects to exclude.
    public var excludedObjects: OneOf_ExcludedObjects? = nil

    /// Initialize a new instance of `BackfillAllStrategy`.
    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 = BackfillAllStrategy().with { $0.oracleExcludedObjects = ... }
    /// ```
    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 oracleExcludedObjects = "oracleExcludedObjects"
      case mysqlExcludedObjects = "mysqlExcludedObjects"
      case postgresqlExcludedObjects = "postgresqlExcludedObjects"
      case sqlServerExcludedObjects = "sqlServerExcludedObjects"
      case salesforceExcludedObjects = "salesforceExcludedObjects"
      case mongodbExcludedObjects = "mongodbExcludedObjects"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)

      var excludedObjects: OneOf_ExcludedObjects? = nil
      let excludedObjectsCheckAndSet = {
        if excludedObjects != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'excludedObjects'"))
        }
        excludedObjects = $0
      }
      if let oracleExcludedObjects = try container.decodeIfPresent(
        OracleRdbms?.self, forKey: .oracleExcludedObjects)
      {
        try excludedObjectsCheckAndSet(.oracleExcludedObjects(oracleExcludedObjects))
      }
      if let mysqlExcludedObjects = try container.decodeIfPresent(
        MysqlRdbms?.self, forKey: .mysqlExcludedObjects)
      {
        try excludedObjectsCheckAndSet(.mysqlExcludedObjects(mysqlExcludedObjects))
      }
      if let postgresqlExcludedObjects = try container.decodeIfPresent(
        PostgresqlRdbms?.self, forKey: .postgresqlExcludedObjects)
      {
        try excludedObjectsCheckAndSet(.postgresqlExcludedObjects(postgresqlExcludedObjects))
      }
      if let sqlServerExcludedObjects = try container.decodeIfPresent(
        SqlServerRdbms?.self, forKey: .sqlServerExcludedObjects)
      {
        try excludedObjectsCheckAndSet(.sqlServerExcludedObjects(sqlServerExcludedObjects))
      }
      if let salesforceExcludedObjects = try container.decodeIfPresent(
        SalesforceOrg?.self, forKey: .salesforceExcludedObjects)
      {
        try excludedObjectsCheckAndSet(.salesforceExcludedObjects(salesforceExcludedObjects))
      }
      if let mongodbExcludedObjects = try container.decodeIfPresent(
        MongodbCluster?.self, forKey: .mongodbExcludedObjects)
      {
        try excludedObjectsCheckAndSet(.mongodbExcludedObjects(mongodbExcludedObjects))
      }
      self.excludedObjects = excludedObjects
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)

      if let choice = self.excludedObjects {
        switch choice {
        case .oracleExcludedObjects(let value):
          try container.encode(value, forKey: .oracleExcludedObjects)
        case .mysqlExcludedObjects(let value):
          try container.encode(value, forKey: .mysqlExcludedObjects)
        case .postgresqlExcludedObjects(let value):
          try container.encode(value, forKey: .postgresqlExcludedObjects)
        case .sqlServerExcludedObjects(let value):
          try container.encode(value, forKey: .sqlServerExcludedObjects)
        case .salesforceExcludedObjects(let value):
          try container.encode(value, forKey: .salesforceExcludedObjects)
        case .mongodbExcludedObjects(let value):
          try container.encode(value, forKey: .mongodbExcludedObjects)
        }
      }
    }

    /// List of objects to exclude.
    public enum OneOf_ExcludedObjects: Codable, Equatable, Sendable {
      /// Oracle data source objects to avoid backfilling.
      indirect case oracleExcludedObjects(OracleRdbms?)
      /// MySQL data source objects to avoid backfilling.
      indirect case mysqlExcludedObjects(MysqlRdbms?)
      /// PostgreSQL data source objects to avoid backfilling.
      indirect case postgresqlExcludedObjects(PostgresqlRdbms?)
      /// SQLServer data source objects to avoid backfilling
      indirect case sqlServerExcludedObjects(SqlServerRdbms?)
      /// Salesforce data source objects to avoid backfilling
      indirect case salesforceExcludedObjects(SalesforceOrg?)
      /// MongoDB data source objects to avoid backfilling
      indirect case mongodbExcludedObjects(MongodbCluster?)
    }

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

  /// Backfill strategy to disable automatic backfill for the Stream's objects.
  public struct BackfillNoneStrategy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Initialize a new instance of `BackfillNoneStrategy`.
    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 = BackfillNoneStrategy().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.datastream.v1.Stream.BackfillNoneStrategy"
    }
    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)
    }
  }

  /// Stream state.
  public enum State: Codable, Equatable, Sendable {
    /// Unspecified stream state.
    case unspecified
    /// The stream has been created but has not yet started streaming data.
    case notStarted
    /// The stream is running.
    case running
    /// The stream is paused.
    case paused
    /// The stream is in maintenance mode.
    ///
    /// Updates are rejected on the resource in this state.
    case maintenance
    /// The stream is experiencing an error that is preventing data from being
    /// streamed.
    case failed
    /// The stream has experienced a terminal failure.
    case failedPermanently
    /// The stream is starting, but not yet running.
    case starting
    /// The Stream is no longer reading new events, but still writing events in
    /// the buffer.
    case draining
    /// 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 .notStarted: return 1
      case .running: return 2
      case .paused: return 3
      case .maintenance: return 4
      case .failed: return 5
      case .failedPermanently: return 6
      case .starting: return 7
      case .draining: return 8
      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 .notStarted: return "NOT_STARTED"
      case .running: return "RUNNING"
      case .paused: return "PAUSED"
      case .maintenance: return "MAINTENANCE"
      case .failed: return "FAILED"
      case .failedPermanently: return "FAILED_PERMANENTLY"
      case .starting: return "STARTING"
      case .draining: return "DRAINING"
      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 "NOT_STARTED": self = .notStarted
      case "RUNNING": self = .running
      case "PAUSED": self = .paused
      case "MAINTENANCE": self = .maintenance
      case "FAILED": self = .failed
      case "FAILED_PERMANENTLY": self = .failedPermanently
      case "STARTING": self = .starting
      case "DRAINING": self = .draining
      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 = .notStarted
      case 2: self = .running
      case 3: self = .paused
      case 4: self = .maintenance
      case 5: self = .failed
      case 6: self = .failedPermanently
      case 7: self = .starting
      case 8: self = .draining
      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 .notStarted: return try container.encode(1)
      case .running: return try container.encode(2)
      case .paused: return try container.encode(3)
      case .maintenance: return try container.encode(4)
      case .failed: return try container.encode(5)
      case .failedPermanently: return try container.encode(6)
      case .starting: return try container.encode(7)
      case .draining: return try container.encode(8)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// Stream backfill strategy.
  public enum OneOf_BackfillStrategy: Codable, Equatable, Sendable {
    /// Automatically backfill objects included in the stream source
    /// configuration. Specific objects can be excluded.
    indirect case backfillAll(Stream.BackfillAllStrategy?)
    /// Do not automatically backfill any objects.
    indirect case backfillNone(Stream.BackfillNoneStrategy?)
  }

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