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

/// Configuration parameters to establish connection with an external data
/// source, except the credential attributes.
public struct Connection: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The resource name of the connection in the form of:
  /// `projects/{project_id}/locations/{location_id}/connections/{connection_id}`
  public var name: Swift.String = Swift.String()

  /// User provided display name for the connection.
  public var friendlyName: Swift.String = Swift.String()

  /// User provided description.
  public var description: Swift.String = Swift.String()

  /// Output only. The creation timestamp of the connection.
  public var creationTime: Swift.Int64 = Swift.Int64()

  /// Output only. The last update timestamp of the connection.
  public var lastModifiedTime: Swift.Int64 = Swift.Int64()

  /// Output only. True, if credential is configured for this connection.
  public var hasCredential: Swift.Bool = Swift.Bool()

  /// Properties specific to the underlying data source.
  public var properties: OneOf_Properties? = nil

  /// Initialize a new instance of `Connection`.
  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 = Connection().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 friendlyName = "friendlyName"
    case description = "description"
    case cloudSql = "cloudSql"
    case aws = "aws"
    case azure = "azure"
    case cloudSpanner = "cloudSpanner"
    case cloudResource = "cloudResource"
    case spark = "spark"
    case salesforceDataCloud = "salesforceDataCloud"
    case creationTime = "creationTime"
    case lastModifiedTime = "lastModifiedTime"
    case hasCredential = "hasCredential"
  }

  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.friendlyName = try container.decode(Swift.String.self, forKey: .friendlyName)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.creationTime = try container.decode(Swift.Int64.self, forKey: .creationTime)
    self.lastModifiedTime = try container.decode(Swift.Int64.self, forKey: .lastModifiedTime)
    self.hasCredential = try container.decode(Swift.Bool.self, forKey: .hasCredential)

    var properties: OneOf_Properties? = nil
    let propertiesCheckAndSet = {
      if properties != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'properties'"))
      }
      properties = $0
    }
    if let cloudSql = try container.decodeIfPresent(CloudSqlProperties?.self, forKey: .cloudSql) {
      try propertiesCheckAndSet(.cloudSql(cloudSql))
    }
    if let aws = try container.decodeIfPresent(AwsProperties?.self, forKey: .aws) {
      try propertiesCheckAndSet(.aws(aws))
    }
    if let azure = try container.decodeIfPresent(AzureProperties?.self, forKey: .azure) {
      try propertiesCheckAndSet(.azure(azure))
    }
    if let cloudSpanner = try container.decodeIfPresent(
      CloudSpannerProperties?.self, forKey: .cloudSpanner)
    {
      try propertiesCheckAndSet(.cloudSpanner(cloudSpanner))
    }
    if let cloudResource = try container.decodeIfPresent(
      CloudResourceProperties?.self, forKey: .cloudResource)
    {
      try propertiesCheckAndSet(.cloudResource(cloudResource))
    }
    if let spark = try container.decodeIfPresent(SparkProperties?.self, forKey: .spark) {
      try propertiesCheckAndSet(.spark(spark))
    }
    if let salesforceDataCloud = try container.decodeIfPresent(
      SalesforceDataCloudProperties?.self, forKey: .salesforceDataCloud)
    {
      try propertiesCheckAndSet(.salesforceDataCloud(salesforceDataCloud))
    }
    self.properties = properties
  }

  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.friendlyName, forKey: .friendlyName)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.creationTime, forKey: .creationTime)
    try container.encode(self.lastModifiedTime, forKey: .lastModifiedTime)
    try container.encode(self.hasCredential, forKey: .hasCredential)

    if let choice = self.properties {
      switch choice {
      case .cloudSql(let value):
        try container.encode(value, forKey: .cloudSql)
      case .aws(let value):
        try container.encode(value, forKey: .aws)
      case .azure(let value):
        try container.encode(value, forKey: .azure)
      case .cloudSpanner(let value):
        try container.encode(value, forKey: .cloudSpanner)
      case .cloudResource(let value):
        try container.encode(value, forKey: .cloudResource)
      case .spark(let value):
        try container.encode(value, forKey: .spark)
      case .salesforceDataCloud(let value):
        try container.encode(value, forKey: .salesforceDataCloud)
      }
    }
  }

  /// Properties specific to the underlying data source.
  public enum OneOf_Properties: Codable, Equatable, Sendable {
    /// Cloud SQL properties.
    indirect case cloudSql(CloudSqlProperties?)
    /// Amazon Web Services (AWS) properties.
    indirect case aws(AwsProperties?)
    /// Azure properties.
    indirect case azure(AzureProperties?)
    /// Cloud Spanner properties.
    indirect case cloudSpanner(CloudSpannerProperties?)
    /// Cloud Resource properties.
    indirect case cloudResource(CloudResourceProperties?)
    /// Spark properties.
    indirect case spark(SparkProperties?)
    /// Optional. Salesforce DataCloud properties. This field is intended for
    /// use only by Salesforce partner projects. This field contains properties
    /// for your Salesforce DataCloud connection.
    indirect case salesforceDataCloud(SalesforceDataCloudProperties?)
  }

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