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

/// Spec for a data discovery scan.
public struct DataDiscoverySpec: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. Configuration for metadata publishing.
  public var bigqueryPublishingConfig: DataDiscoverySpec.BigQueryPublishingConfig? = nil

  /// The configurations of the data discovery scan resource.
  public var resourceConfig: OneOf_ResourceConfig? = nil

  /// Initialize a new instance of `DataDiscoverySpec`.
  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 = DataDiscoverySpec().with { $0.bigqueryPublishingConfig = ... }
  /// ```
  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 bigqueryPublishingConfig = "bigqueryPublishingConfig"
    case storageConfig = "storageConfig"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.bigqueryPublishingConfig = try container.decodeIfPresent(
      DataDiscoverySpec.BigQueryPublishingConfig.self, forKey: .bigqueryPublishingConfig)

    var resourceConfig: OneOf_ResourceConfig? = nil
    let resourceConfigCheckAndSet = {
      if resourceConfig != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'resourceConfig'"))
      }
      resourceConfig = $0
    }
    if let storageConfig = try container.decodeIfPresent(
      DataDiscoverySpec.StorageConfig?.self, forKey: .storageConfig)
    {
      try resourceConfigCheckAndSet(.storageConfig(storageConfig))
    }
    self.resourceConfig = resourceConfig
  }

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

    if let choice = self.resourceConfig {
      switch choice {
      case .storageConfig(let value):
        try container.encode(value, forKey: .storageConfig)
      }
    }
  }

  /// Describes BigQuery publishing configurations.
  public struct BigQueryPublishingConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Determines whether to  publish discovered tables as BigLake
    /// external tables or non-BigLake external tables.
    public var tableType: DataDiscoverySpec.BigQueryPublishingConfig.TableType = DataDiscoverySpec
      .BigQueryPublishingConfig.TableType()

    /// Optional. The BigQuery connection used to create BigLake tables.
    /// Must be in the form
    /// `projects/{project_id}/locations/{location_id}/connections/{connection_id}`
    public var connection: Swift.String = Swift.String()

    /// Optional. The location of the BigQuery dataset to publish BigLake
    /// external or non-BigLake external tables to.
    /// 1. If the Cloud Storage bucket is located in a multi-region bucket, then
    /// BigQuery dataset can be in the same multi-region bucket or any single
    /// region that is included in the same multi-region bucket. The datascan can
    /// be created in any single region that is included in the same multi-region
    /// bucket
    /// 2. If the Cloud Storage bucket is located in a dual-region bucket, then
    /// BigQuery dataset can be located in regions that are included in the
    /// dual-region bucket, or in a multi-region that includes the dual-region.
    /// The datascan can be created in any single region that is included in the
    /// same dual-region bucket.
    /// 3. If the Cloud Storage bucket is located in a single region, then
    /// BigQuery dataset can be in the same single region or any multi-region
    /// bucket that includes the same single region. The datascan will be created
    /// in the same single region as the bucket.
    /// 4. If the BigQuery dataset is in single region, it must be in the same
    /// single region as the datascan.
    ///
    /// For supported values, refer to
    /// https://cloud.google.com/bigquery/docs/locations#supported_locations.
    public var location: Swift.String = Swift.String()

    /// Optional. The project of the BigQuery dataset to publish BigLake external
    /// or non-BigLake external tables to. If not specified, the project of the
    /// Cloud Storage bucket will be used. The format is
    /// "projects/{project_id_or_number}".
    public var project: Swift.String = Swift.String()

    /// Initialize a new instance of `BigQueryPublishingConfig`.
    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 = BigQueryPublishingConfig().with { $0.tableType = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    /// Determines how discovered tables are published.
    public enum TableType: Codable, Equatable, Sendable {
      /// Table type unspecified.
      case unspecified
      /// Default. Discovered tables are published as BigQuery external tables
      /// whose data is accessed using the credentials of the user querying the
      /// table.
      case external
      /// Discovered tables are published as BigLake external tables whose data
      /// is accessed using the credentials of the associated BigQuery
      /// connection.
      case biglake
      /// 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 .external: return 1
        case .biglake: 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 "TABLE_TYPE_UNSPECIFIED"
        case .external: return "EXTERNAL"
        case .biglake: return "BIGLAKE"
        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:TableType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "TABLE_TYPE_UNSPECIFIED": self = .unspecified
        case "EXTERNAL": self = .external
        case "BIGLAKE": self = .biglake
        default: self = .unknownStringValue(stringValue)
        }
      }

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

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

  /// Configurations related to Cloud Storage as the data source.
  public struct StorageConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Defines the data to include during discovery when only a subset
    /// of the data should be considered. Provide a list of patterns that
    /// identify the data to include. For Cloud Storage bucket assets, these
    /// patterns are interpreted as glob patterns used to match object names. For
    /// BigQuery dataset assets, these patterns are interpreted as patterns to
    /// match table names.
    public var includePatterns: [Swift.String] = []

    /// Optional. Defines the data to exclude during discovery. Provide a list of
    /// patterns that identify the data to exclude. For Cloud Storage bucket
    /// assets, these patterns are interpreted as glob patterns used to match
    /// object names. For BigQuery dataset assets, these patterns are interpreted
    /// as patterns to match table names.
    public var excludePatterns: [Swift.String] = []

    /// Optional. Configuration for CSV data.
    public var csvOptions: DataDiscoverySpec.StorageConfig.CsvOptions? = nil

    /// Optional. Configuration for JSON data.
    public var jsonOptions: DataDiscoverySpec.StorageConfig.JsonOptions? = nil

    /// Optional. Specifies configuration for unstructured data discovery.
    public var unstructuredDataOptions: DataDiscoverySpec.StorageConfig.UnstructuredDataOptions? =
      nil

    /// Initialize a new instance of `StorageConfig`.
    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 = StorageConfig().with { $0.includePatterns = ... }
    /// ```
    public func with(_ config: (inout Self) throws -> Swift.Void) rethrows -> Self {
      var copy = self
      try config(&copy)
      return copy
    }

    /// Describes CSV and similar semi-structured data formats.
    public struct CsvOptions: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Optional. The number of rows to interpret as header rows that should be
      /// skipped when reading data rows.
      public var headerRows: Swift.Int32 = Swift.Int32()

      /// Optional. The delimiter that is used to separate values. The default is
      /// `,` (comma).
      public var delimiter: Swift.String = Swift.String()

      /// Optional. The character encoding of the data. The default is UTF-8.
      public var encoding: Swift.String = Swift.String()

      /// Optional. Whether to disable the inference of data types for CSV data.
      /// If true, all columns are registered as strings.
      public var typeInferenceDisabled: Swift.Bool = Swift.Bool()

      /// Optional. The character used to quote column values. Accepts `"`
      /// (double quotation mark) or `'` (single quotation mark). If unspecified,
      /// defaults to `"` (double quotation mark).
      public var quote: Swift.String = Swift.String()

      /// Initialize a new instance of `CsvOptions`.
      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 = CsvOptions().with { $0.headerRows = ... }
      /// ```
      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.dataplex.v1.DataDiscoverySpec.StorageConfig.CsvOptions"
      }
      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)
      }
    }

    /// Describes JSON data format.
    public struct JsonOptions: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Optional. The character encoding of the data. The default is UTF-8.
      public var encoding: Swift.String = Swift.String()

      /// Optional. Whether to disable the inference of data types for JSON data.
      /// If true, all columns are registered as their primitive types
      /// (strings, number, or boolean).
      public var typeInferenceDisabled: Swift.Bool = Swift.Bool()

      /// Initialize a new instance of `JsonOptions`.
      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 = JsonOptions().with { $0.encoding = ... }
      /// ```
      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.dataplex.v1.DataDiscoverySpec.StorageConfig.JsonOptions"
      }
      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)
      }
    }

    /// Describes options for unstructured data discovery.
    public struct UnstructuredDataOptions: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Optional. Specifies whether deeper semantic inference over the objects'
      /// contents using GenAI is enabled.
      public var semanticInferenceEnabled: Swift.Bool = Swift.Bool()

      /// Initialize a new instance of `UnstructuredDataOptions`.
      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 = UnstructuredDataOptions().with { $0.semanticInferenceEnabled = ... }
      /// ```
      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.dataplex.v1.DataDiscoverySpec.StorageConfig.UnstructuredDataOptions"
      }
      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)
      }
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.dataplex.v1.DataDiscoverySpec.StorageConfig"
    }
    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 configurations of the data discovery scan resource.
  public enum OneOf_ResourceConfig: Codable, Equatable, Sendable {
    /// Cloud Storage related configurations.
    indirect case storageConfig(DataDiscoverySpec.StorageConfig?)
  }

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