// 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 properties of GoldengateMicrosoftSqlserverConnection.
public struct GoldengateMicrosoftSqlserverConnectionProperties: Codable, Equatable, GoogleCloudWkt
    ._AnyPackable,
  Sendable
{
  /// Optional. The technology type of MicrosoftSqlserverConnection.
  public var technologyType: Swift.String = Swift.String()

  /// Optional. The name of the database.
  public var database: Swift.String = Swift.String()

  /// Optional. The name or address of a host.
  public var host: Swift.String = Swift.String()

  /// Optional. The port of an endpoint usually specified for a connection.
  public var port: Swift.Int32 = Swift.Int32()

  /// Optional. The username Oracle Goldengate uses to connect to the Microsoft
  /// SQL Server.
  public var username: Swift.String = Swift.String()

  /// Optional. An array of name-value pair attribute entries.
  /// Used as additional parameters in connection string.
  public var additionalAttributes: [NameValuePair] = []

  /// Optional. Security Type for Microsoft SQL Server.
  public var securityProtocol:
    GoldengateMicrosoftSqlserverConnectionProperties.MicrosoftSqlserverSecurityProtocol =
      GoldengateMicrosoftSqlserverConnectionProperties.MicrosoftSqlserverSecurityProtocol()

  /// Optional. Database Certificate - The base64 encoded content of a .pem or
  /// .crt file containing the server public key (for 1-way SSL).
  public var sslCaFile: Swift.String = Swift.String()

  /// Optional. If set to true, the driver validates the certificate that is sent
  /// by the database server.
  public var serverCertificateValidationRequired: Swift.Bool = Swift.Bool()

  /// The password Oracle Goldengate uses to connect the associated Microsoft
  /// SQL Server.
  public var connectionPasswordOptions: OneOf_ConnectionPasswordOptions? = nil

  /// Initialize a new instance of `GoldengateMicrosoftSqlserverConnectionProperties`.
  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 = GoldengateMicrosoftSqlserverConnectionProperties().with { $0.password = ... }
  /// ```
  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 password = "password"
    case passwordSecretVersion = "passwordSecretVersion"
    case technologyType = "technologyType"
    case database = "database"
    case host = "host"
    case port = "port"
    case username = "username"
    case additionalAttributes = "additionalAttributes"
    case securityProtocol = "securityProtocol"
    case sslCaFile = "sslCaFile"
    case serverCertificateValidationRequired = "serverCertificateValidationRequired"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.technologyType = try container.decode(Swift.String.self, forKey: .technologyType)
    self.database = try container.decode(Swift.String.self, forKey: .database)
    self.host = try container.decode(Swift.String.self, forKey: .host)
    self.port = try container.decode(Swift.Int32.self, forKey: .port)
    self.username = try container.decode(Swift.String.self, forKey: .username)
    self.additionalAttributes = try container.decode(
      [NameValuePair].self, forKey: .additionalAttributes)
    self.securityProtocol = try container.decode(
      GoldengateMicrosoftSqlserverConnectionProperties.MicrosoftSqlserverSecurityProtocol.self,
      forKey: .securityProtocol)
    self.sslCaFile = try container.decode(Swift.String.self, forKey: .sslCaFile)
    self.serverCertificateValidationRequired = try container.decode(
      Swift.Bool.self, forKey: .serverCertificateValidationRequired)

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

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.technologyType, forKey: .technologyType)
    try container.encode(self.database, forKey: .database)
    try container.encode(self.host, forKey: .host)
    try container.encode(self.port, forKey: .port)
    try container.encode(self.username, forKey: .username)
    try container.encode(self.additionalAttributes, forKey: .additionalAttributes)
    try container.encode(self.securityProtocol, forKey: .securityProtocol)
    try container.encode(self.sslCaFile, forKey: .sslCaFile)
    try container.encode(
      self.serverCertificateValidationRequired, forKey: .serverCertificateValidationRequired)

    if let choice = self.connectionPasswordOptions {
      switch choice {
      case .password(let value):
        try container.encode(value, forKey: .password)
      case .passwordSecretVersion(let value):
        try container.encode(value, forKey: .passwordSecretVersion)
      }
    }
  }

  /// Enum for Security Type for Microsoft SQL Server.
  public enum MicrosoftSqlserverSecurityProtocol: Codable, Equatable, Sendable {
    /// Security type not specified.
    case unspecified
    /// Plain text communication.
    case plain
    /// Transport Layer Security.
    case tls
    /// 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 .plain: return 1
      case .tls: 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 "MICROSOFT_SQLSERVER_SECURITY_PROTOCOL_UNSPECIFIED"
      case .plain: return "PLAIN"
      case .tls: return "TLS"
      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:MicrosoftSqlserverSecurityProtocol/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "MICROSOFT_SQLSERVER_SECURITY_PROTOCOL_UNSPECIFIED": self = .unspecified
      case "PLAIN": self = .plain
      case "TLS": self = .tls
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  /// The password Oracle Goldengate uses to connect the associated Microsoft
  /// SQL Server.
  public enum OneOf_ConnectionPasswordOptions: Codable, Equatable, Sendable {
    /// Optional. Input only. The password Oracle Goldengate uses for Microsoft
    /// SQL Server connection in plain text.
    case password(Swift.String)
    /// Optional. Input only. The resource name of a secret version in Secret
    /// Manager which contains the password Oracle Goldengate uses for Microsoft
    /// SQL Server connection. Format:
    /// projects/{project}/secrets/{secret}/versions/{version}.
    case passwordSecretVersion(Swift.String)
  }

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