// 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 GoldengatePostgresqlConnection.
public struct GoldengatePostgresqlConnectionProperties: Codable, Equatable, GoogleCloudWkt
    ._AnyPackable,
  Sendable
{
  /// Optional. The technology type of PostgresqlConnection.
  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 the associated
  /// system of the given technology.
  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 protocol for PostgreSQL.
  public var securityProtocol: GoldengatePostgresqlConnectionProperties.PostgresqlSecurityProtocol =
    GoldengatePostgresqlConnectionProperties.PostgresqlSecurityProtocol()

  /// Optional. SSL modes for PostgreSQL.
  public var sslMode: GoldengatePostgresqlConnectionProperties.PostgresqlSslMode =
    GoldengatePostgresqlConnectionProperties.PostgresqlSslMode()

  /// Optional. The base64 encoded certificate of the trusted certificate
  /// authorities (Trusted CA) for PostgreSQL.
  public var sslCaFile: Swift.String = Swift.String()

  /// Optional. The base64 encoded list of certificates revoked by the trusted
  /// certificate authorities (Trusted CA).
  public var sslCrlFile: Swift.String = Swift.String()

  /// Optional. The base64 encoded certificate of the PostgreSQL server.
  public var sslCertFile: Swift.String = Swift.String()

  /// Optional. The base64 encoded private key of the PostgreSQL server.
  public var sslKeyFile: Swift.String = Swift.String()

  /// Optional. The OCID of the database system being referenced.
  public var dbSystemId: Swift.String = Swift.String()

  /// The password Oracle Goldengate uses to connect the associated system of
  /// the given technology.
  public var connectionPasswordOptions: OneOf_ConnectionPasswordOptions? = nil

  /// Initialize a new instance of `GoldengatePostgresqlConnectionProperties`.
  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 = GoldengatePostgresqlConnectionProperties().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 sslMode = "sslMode"
    case sslCaFile = "sslCaFile"
    case sslCrlFile = "sslCrlFile"
    case sslCertFile = "sslCertFile"
    case sslKeyFile = "sslKeyFile"
    case dbSystemId = "dbSystemId"
  }

  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(
      GoldengatePostgresqlConnectionProperties.PostgresqlSecurityProtocol.self,
      forKey: .securityProtocol)
    self.sslMode = try container.decode(
      GoldengatePostgresqlConnectionProperties.PostgresqlSslMode.self, forKey: .sslMode)
    self.sslCaFile = try container.decode(Swift.String.self, forKey: .sslCaFile)
    self.sslCrlFile = try container.decode(Swift.String.self, forKey: .sslCrlFile)
    self.sslCertFile = try container.decode(Swift.String.self, forKey: .sslCertFile)
    self.sslKeyFile = try container.decode(Swift.String.self, forKey: .sslKeyFile)
    self.dbSystemId = try container.decode(Swift.String.self, forKey: .dbSystemId)

    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.sslMode, forKey: .sslMode)
    try container.encode(self.sslCaFile, forKey: .sslCaFile)
    try container.encode(self.sslCrlFile, forKey: .sslCrlFile)
    try container.encode(self.sslCertFile, forKey: .sslCertFile)
    try container.encode(self.sslKeyFile, forKey: .sslKeyFile)
    try container.encode(self.dbSystemId, forKey: .dbSystemId)

    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 protocol for PostgreSQL.
  public enum PostgresqlSecurityProtocol: Codable, Equatable, Sendable {
    /// Security protocol not specified.
    case unspecified
    /// Plain text communication.
    case plain
    /// Transport Layer Security.
    case tls
    /// Mutual Transport Layer Security.
    case mtls
    /// 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 .mtls: 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 "POSTGRESQL_SECURITY_PROTOCOL_UNSPECIFIED"
      case .plain: return "PLAIN"
      case .tls: return "TLS"
      case .mtls: return "MTLS"
      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:PostgresqlSecurityProtocol/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "POSTGRESQL_SECURITY_PROTOCOL_UNSPECIFIED": self = .unspecified
      case "PLAIN": self = .plain
      case "TLS": self = .tls
      case "MTLS": self = .mtls
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  /// Enum for SSL modes for PostgreSQL.
  public enum PostgresqlSslMode: Codable, Equatable, Sendable {
    /// SSL mode not specified.
    case unspecified
    /// Prefer SSL.
    case prefer
    /// Require SSL.
    case require
    /// Verify Certificate Authority.
    case verifyCa
    /// Verify Full.
    case verifyFull
    /// 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 .prefer: return 1
      case .require: return 2
      case .verifyCa: return 3
      case .verifyFull: return 4
      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 "POSTGRESQL_SSL_MODE_UNSPECIFIED"
      case .prefer: return "PREFER"
      case .require: return "REQUIRE"
      case .verifyCa: return "VERIFY_CA"
      case .verifyFull: return "VERIFY_FULL"
      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:PostgresqlSslMode/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "POSTGRESQL_SSL_MODE_UNSPECIFIED": self = .unspecified
      case "PREFER": self = .prefer
      case "REQUIRE": self = .require
      case "VERIFY_CA": self = .verifyCa
      case "VERIFY_FULL": self = .verifyFull
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:PostgresqlSslMode/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .prefer
      case 2: self = .require
      case 3: self = .verifyCa
      case 4: self = .verifyFull
      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 .prefer: return try container.encode(1)
      case .require: return try container.encode(2)
      case .verifyCa: return try container.encode(3)
      case .verifyFull: return try container.encode(4)
      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 system of
  /// the given technology.
  public enum OneOf_ConnectionPasswordOptions: Codable, Equatable, Sendable {
    /// Optional. Input only. The password Oracle Goldengate uses for PostgreSQL
    /// 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 PostgreSQL
    /// 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.GoldengatePostgresqlConnectionProperties"
  }
  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)
  }
}
