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

/// A column within a schema. Columns can be nested inside
/// other columns.
public struct ColumnSchema: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Name of the column.
  ///
  /// Must be a UTF-8 string without dots (.).
  /// The maximum size is 64 bytes.
  public var column: Swift.String = Swift.String()

  /// Required. Type of the column.
  ///
  /// Must be a UTF-8 string with the maximum size of 128 bytes.
  public var type: Swift.String = Swift.String()

  /// Optional. Description of the column. Default value is an empty string.
  ///
  /// The description must be a UTF-8 string with the maximum size of 2000
  /// bytes.
  public var description: Swift.String = Swift.String()

  /// Optional. A column's mode indicates whether values in this column are
  /// required, nullable, or repeated.
  ///
  /// Only `NULLABLE`, `REQUIRED`, and `REPEATED` values are supported.
  /// Default mode is `NULLABLE`.
  public var mode: Swift.String = Swift.String()

  /// Optional. Default value for the column.
  public var defaultValue: Swift.String = Swift.String()

  /// Optional. Ordinal position
  public var ordinalPosition: Swift.Int32 = Swift.Int32()

  /// Optional. Most important inclusion of this column.
  public var highestIndexingType: ColumnSchema.IndexingType = ColumnSchema.IndexingType()

  /// Optional. Schema of sub-columns. A column can have zero or more
  /// sub-columns.
  public var subcolumns: [ColumnSchema] = []

  /// Optional. The subtype of the RANGE, if the type of this field is RANGE. If
  /// the type is RANGE, this field is required. Possible values for the field
  /// element type of a RANGE include:
  /// * DATE
  /// * DATETIME
  /// * TIMESTAMP
  public var rangeElementType: ColumnSchema.FieldElementType? = nil

  /// Optional. Garbage collection policy for the column or column family.
  /// Applies to systems like Cloud Bigtable.
  public var gcRule: Swift.String = Swift.String()

  /// Information only applying for columns in Entries from a specific system.
  public var systemSpec: OneOf_SystemSpec? = nil

  /// Initialize a new instance of `ColumnSchema`.
  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 = ColumnSchema().with { $0.column = ... }
  /// ```
  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 column = "column"
    case type = "type"
    case description = "description"
    case mode = "mode"
    case defaultValue = "defaultValue"
    case ordinalPosition = "ordinalPosition"
    case highestIndexingType = "highestIndexingType"
    case subcolumns = "subcolumns"
    case lookerColumnSpec = "lookerColumnSpec"
    case rangeElementType = "rangeElementType"
    case gcRule = "gcRule"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.column = try container.decode(Swift.String.self, forKey: .column)
    self.type = try container.decode(Swift.String.self, forKey: .type)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.mode = try container.decode(Swift.String.self, forKey: .mode)
    self.defaultValue = try container.decode(Swift.String.self, forKey: .defaultValue)
    self.ordinalPosition = try container.decode(Swift.Int32.self, forKey: .ordinalPosition)
    self.highestIndexingType = try container.decode(
      ColumnSchema.IndexingType.self, forKey: .highestIndexingType)
    self.subcolumns = try container.decode([ColumnSchema].self, forKey: .subcolumns)
    self.rangeElementType = try container.decodeIfPresent(
      ColumnSchema.FieldElementType.self, forKey: .rangeElementType)
    self.gcRule = try container.decode(Swift.String.self, forKey: .gcRule)

    var systemSpec: OneOf_SystemSpec? = nil
    let systemSpecCheckAndSet = {
      if systemSpec != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'systemSpec'"))
      }
      systemSpec = $0
    }
    if let lookerColumnSpec = try container.decodeIfPresent(
      ColumnSchema.LookerColumnSpec?.self, forKey: .lookerColumnSpec)
    {
      try systemSpecCheckAndSet(.lookerColumnSpec(lookerColumnSpec))
    }
    self.systemSpec = systemSpec
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.column, forKey: .column)
    try container.encode(self.type, forKey: .type)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.mode, forKey: .mode)
    try container.encode(self.defaultValue, forKey: .defaultValue)
    try container.encode(self.ordinalPosition, forKey: .ordinalPosition)
    try container.encode(self.highestIndexingType, forKey: .highestIndexingType)
    try container.encode(self.subcolumns, forKey: .subcolumns)
    try container.encode(self.rangeElementType, forKey: .rangeElementType)
    try container.encode(self.gcRule, forKey: .gcRule)

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

  /// Column info specific to Looker System.
  public struct LookerColumnSpec: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Looker specific column type of this column.
    public var type: ColumnSchema.LookerColumnSpec.LookerColumnType = ColumnSchema.LookerColumnSpec
      .LookerColumnType()

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

    /// Column type in Looker.
    public enum LookerColumnType: Codable, Equatable, Sendable {
      /// Unspecified.
      case unspecified
      /// Dimension.
      case dimension
      /// Dimension group - parent for Dimension.
      case dimensionGroup
      /// Filter.
      case filter
      /// Measure.
      case measure
      /// Parameter.
      case parameter
      /// 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 .dimension: return 1
        case .dimensionGroup: return 2
        case .filter: return 3
        case .measure: return 4
        case .parameter: return 5
        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 "LOOKER_COLUMN_TYPE_UNSPECIFIED"
        case .dimension: return "DIMENSION"
        case .dimensionGroup: return "DIMENSION_GROUP"
        case .filter: return "FILTER"
        case .measure: return "MEASURE"
        case .parameter: return "PARAMETER"
        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:LookerColumnType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "LOOKER_COLUMN_TYPE_UNSPECIFIED": self = .unspecified
        case "DIMENSION": self = .dimension
        case "DIMENSION_GROUP": self = .dimensionGroup
        case "FILTER": self = .filter
        case "MEASURE": self = .measure
        case "PARAMETER": self = .parameter
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:LookerColumnType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .dimension
        case 2: self = .dimensionGroup
        case 3: self = .filter
        case 4: self = .measure
        case 5: self = .parameter
        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 .dimension: return try container.encode(1)
        case .dimensionGroup: return try container.encode(2)
        case .filter: return try container.encode(3)
        case .measure: return try container.encode(4)
        case .parameter: return try container.encode(5)
        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.datacatalog.v1.ColumnSchema.LookerColumnSpec"
    }
    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)
    }
  }

  /// Represents the type of a field element.
  public struct FieldElementType: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The type of a field element. See
    /// [ColumnSchema.type][google.cloud.datacatalog.v1.ColumnSchema.type].
    ///
    /// [google.cloud.datacatalog.v1.ColumnSchema.type]: <doc:ColumnSchema/type>
    public var type: Swift.String = Swift.String()

    /// Initialize a new instance of `FieldElementType`.
    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 = FieldElementType().with { $0.type = ... }
    /// ```
    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.datacatalog.v1.ColumnSchema.FieldElementType"
    }
    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)
    }
  }

  /// Specifies inclusion of the column in an index
  public enum IndexingType: Codable, Equatable, Sendable {
    /// Unspecified.
    case unspecified
    /// Column not a part of an index.
    case `none`
    /// Column Part of non unique index.
    case nonUnique
    /// Column part of unique index.
    case unique
    /// Column part of the primary key.
    case primaryKey
    /// 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 .`none`: return 1
      case .nonUnique: return 2
      case .unique: return 3
      case .primaryKey: 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 "INDEXING_TYPE_UNSPECIFIED"
      case .`none`: return "INDEXING_TYPE_NONE"
      case .nonUnique: return "INDEXING_TYPE_NON_UNIQUE"
      case .unique: return "INDEXING_TYPE_UNIQUE"
      case .primaryKey: return "INDEXING_TYPE_PRIMARY_KEY"
      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:IndexingType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "INDEXING_TYPE_UNSPECIFIED": self = .unspecified
      case "INDEXING_TYPE_NONE": self = .`none`
      case "INDEXING_TYPE_NON_UNIQUE": self = .nonUnique
      case "INDEXING_TYPE_UNIQUE": self = .unique
      case "INDEXING_TYPE_PRIMARY_KEY": self = .primaryKey
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  /// Information only applying for columns in Entries from a specific system.
  public enum OneOf_SystemSpec: Codable, Equatable, Sendable {
    /// Looker specific column info of this column.
    indirect case lookerColumnSpec(ColumnSchema.LookerColumnSpec?)
  }

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