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

/// The strategy that the stream uses for CDC replication.
public struct CdcStrategy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The position to start reading from when starting, resuming, or recovering
  /// the stream.
  /// If not set, the system's default value will be used.
  public var startPosition: OneOf_StartPosition? = nil

  /// Initialize a new instance of `CdcStrategy`.
  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 = CdcStrategy().with { $0.mostRecentStartPosition = ... }
  /// ```
  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 mostRecentStartPosition = "mostRecentStartPosition"
    case nextAvailableStartPosition = "nextAvailableStartPosition"
    case specificStartPosition = "specificStartPosition"
  }

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

    var startPosition: OneOf_StartPosition? = nil
    let startPositionCheckAndSet = {
      if startPosition != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'startPosition'"))
      }
      startPosition = $0
    }
    if let mostRecentStartPosition = try container.decodeIfPresent(
      CdcStrategy.MostRecentStartPosition?.self, forKey: .mostRecentStartPosition)
    {
      try startPositionCheckAndSet(.mostRecentStartPosition(mostRecentStartPosition))
    }
    if let nextAvailableStartPosition = try container.decodeIfPresent(
      CdcStrategy.NextAvailableStartPosition?.self, forKey: .nextAvailableStartPosition)
    {
      try startPositionCheckAndSet(.nextAvailableStartPosition(nextAvailableStartPosition))
    }
    if let specificStartPosition = try container.decodeIfPresent(
      CdcStrategy.SpecificStartPosition?.self, forKey: .specificStartPosition)
    {
      try startPositionCheckAndSet(.specificStartPosition(specificStartPosition))
    }
    self.startPosition = startPosition
  }

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

    if let choice = self.startPosition {
      switch choice {
      case .mostRecentStartPosition(let value):
        try container.encode(value, forKey: .mostRecentStartPosition)
      case .nextAvailableStartPosition(let value):
        try container.encode(value, forKey: .nextAvailableStartPosition)
      case .specificStartPosition(let value):
        try container.encode(value, forKey: .specificStartPosition)
      }
    }
  }

  /// CDC strategy to start replicating from the most recent position in the
  /// source.
  public struct MostRecentStartPosition: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Initialize a new instance of `MostRecentStartPosition`.
    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 = MostRecentStartPosition().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.CdcStrategy.MostRecentStartPosition"
    }
    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)
    }
  }

  /// CDC strategy to resume replication from the next available position in the
  /// source.
  public struct NextAvailableStartPosition: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Initialize a new instance of `NextAvailableStartPosition`.
    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 = NextAvailableStartPosition().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.CdcStrategy.NextAvailableStartPosition"
    }
    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)
    }
  }

  /// CDC strategy to start replicating from a specific position in the source.
  public struct SpecificStartPosition: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    public var position: OneOf_Position? = nil

    /// Initialize a new instance of `SpecificStartPosition`.
    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 = SpecificStartPosition().with { $0.mysqlLogPosition = ... }
    /// ```
    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 mysqlLogPosition = "mysqlLogPosition"
      case oracleScnPosition = "oracleScnPosition"
      case sqlServerLsnPosition = "sqlServerLsnPosition"
      case mysqlGtidPosition = "mysqlGtidPosition"
    }

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

      var position: OneOf_Position? = nil
      let positionCheckAndSet = {
        if position != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'position'"))
        }
        position = $0
      }
      if let mysqlLogPosition = try container.decodeIfPresent(
        MysqlLogPosition?.self, forKey: .mysqlLogPosition)
      {
        try positionCheckAndSet(.mysqlLogPosition(mysqlLogPosition))
      }
      if let oracleScnPosition = try container.decodeIfPresent(
        OracleScnPosition?.self, forKey: .oracleScnPosition)
      {
        try positionCheckAndSet(.oracleScnPosition(oracleScnPosition))
      }
      if let sqlServerLsnPosition = try container.decodeIfPresent(
        SqlServerLsnPosition?.self, forKey: .sqlServerLsnPosition)
      {
        try positionCheckAndSet(.sqlServerLsnPosition(sqlServerLsnPosition))
      }
      if let mysqlGtidPosition = try container.decodeIfPresent(
        MysqlGtidPosition?.self, forKey: .mysqlGtidPosition)
      {
        try positionCheckAndSet(.mysqlGtidPosition(mysqlGtidPosition))
      }
      self.position = position
    }

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

      if let choice = self.position {
        switch choice {
        case .mysqlLogPosition(let value):
          try container.encode(value, forKey: .mysqlLogPosition)
        case .oracleScnPosition(let value):
          try container.encode(value, forKey: .oracleScnPosition)
        case .sqlServerLsnPosition(let value):
          try container.encode(value, forKey: .sqlServerLsnPosition)
        case .mysqlGtidPosition(let value):
          try container.encode(value, forKey: .mysqlGtidPosition)
        }
      }
    }

    public enum OneOf_Position: Codable, Equatable, Sendable {
      /// MySQL specific log position to start replicating from.
      indirect case mysqlLogPosition(MysqlLogPosition?)
      /// Oracle SCN to start replicating from.
      indirect case oracleScnPosition(OracleScnPosition?)
      /// SqlServer LSN to start replicating from.
      indirect case sqlServerLsnPosition(SqlServerLsnPosition?)
      /// MySQL GTID set to start replicating from.
      indirect case mysqlGtidPosition(MysqlGtidPosition?)
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.datastream.v1.CdcStrategy.SpecificStartPosition"
    }
    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 position to start reading from when starting, resuming, or recovering
  /// the stream.
  /// If not set, the system's default value will be used.
  public enum OneOf_StartPosition: Codable, Equatable, Sendable {
    /// Optional. Start replicating from the most recent position in the source.
    indirect case mostRecentStartPosition(CdcStrategy.MostRecentStartPosition?)
    /// Optional. Resume replication from the next available position in the
    /// source.
    indirect case nextAvailableStartPosition(CdcStrategy.NextAvailableStartPosition?)
    /// Optional. Start replicating from a specific position in the source.
    indirect case specificStartPosition(CdcStrategy.SpecificStartPosition?)
  }

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