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

/// SQLServer data source configuration
public struct SqlServerSourceConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// SQLServer objects to include in the stream.
  public var includeObjects: SqlServerRdbms? = nil

  /// SQLServer objects to exclude from the stream.
  public var excludeObjects: SqlServerRdbms? = nil

  /// Max concurrent CDC tasks.
  public var maxConcurrentCdcTasks: Swift.Int32 = Swift.Int32()

  /// Max concurrent backfill tasks.
  public var maxConcurrentBackfillTasks: Swift.Int32 = Swift.Int32()

  /// Configuration to select the CDC read method for the stream.
  public var cdcMethod: OneOf_CdcMethod? = nil

  /// Initialize a new instance of `SqlServerSourceConfig`.
  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 = SqlServerSourceConfig().with { $0.includeObjects = ... }
  /// ```
  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 includeObjects = "includeObjects"
    case excludeObjects = "excludeObjects"
    case maxConcurrentCdcTasks = "maxConcurrentCdcTasks"
    case maxConcurrentBackfillTasks = "maxConcurrentBackfillTasks"
    case transactionLogs = "transactionLogs"
    case changeTables = "changeTables"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.includeObjects = try container.decodeIfPresent(
      SqlServerRdbms.self, forKey: .includeObjects)
    self.excludeObjects = try container.decodeIfPresent(
      SqlServerRdbms.self, forKey: .excludeObjects)
    self.maxConcurrentCdcTasks = try container.decode(
      Swift.Int32.self, forKey: .maxConcurrentCdcTasks)
    self.maxConcurrentBackfillTasks = try container.decode(
      Swift.Int32.self, forKey: .maxConcurrentBackfillTasks)

    var cdcMethod: OneOf_CdcMethod? = nil
    let cdcMethodCheckAndSet = {
      if cdcMethod != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'cdcMethod'"))
      }
      cdcMethod = $0
    }
    if let transactionLogs = try container.decodeIfPresent(
      SqlServerTransactionLogs?.self, forKey: .transactionLogs)
    {
      try cdcMethodCheckAndSet(.transactionLogs(transactionLogs))
    }
    if let changeTables = try container.decodeIfPresent(
      SqlServerChangeTables?.self, forKey: .changeTables)
    {
      try cdcMethodCheckAndSet(.changeTables(changeTables))
    }
    self.cdcMethod = cdcMethod
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.includeObjects, forKey: .includeObjects)
    try container.encode(self.excludeObjects, forKey: .excludeObjects)
    try container.encode(self.maxConcurrentCdcTasks, forKey: .maxConcurrentCdcTasks)
    try container.encode(self.maxConcurrentBackfillTasks, forKey: .maxConcurrentBackfillTasks)

    if let choice = self.cdcMethod {
      switch choice {
      case .transactionLogs(let value):
        try container.encode(value, forKey: .transactionLogs)
      case .changeTables(let value):
        try container.encode(value, forKey: .changeTables)
      }
    }
  }

  /// Configuration to select the CDC read method for the stream.
  public enum OneOf_CdcMethod: Codable, Equatable, Sendable {
    /// CDC reader reads from transaction logs.
    indirect case transactionLogs(SqlServerTransactionLogs?)
    /// CDC reader reads from change tables.
    indirect case changeTables(SqlServerChangeTables?)
  }

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