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

/// Defines the properties and custom parameters for a data source.
public struct DataSource: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. Data source resource name.
  public var name: Swift.String = Swift.String()

  /// Data source id.
  public var dataSourceId: Swift.String = Swift.String()

  /// User friendly data source name.
  public var displayName: Swift.String = Swift.String()

  /// User friendly data source description string.
  public var description: Swift.String = Swift.String()

  /// Data source client id which should be used to receive refresh token.
  public var clientId: Swift.String = Swift.String()

  /// Api auth scopes for which refresh token needs to be obtained. These are
  /// scopes needed by a data source to prepare data and ingest them into
  /// BigQuery, e.g., https://www.googleapis.com/auth/bigquery
  public var scopes: [Swift.String] = []

  /// Deprecated. This field has no effect.
  @available(*, deprecated)
  public var transferType: TransferType = TransferType()

  /// Deprecated. This field has no effect.
  @available(*, deprecated)
  public var supportsMultipleTransfers: Swift.Bool = Swift.Bool()

  /// The number of seconds to wait for an update from the data source
  /// before the Data Transfer Service marks the transfer as FAILED.
  public var updateDeadlineSeconds: Swift.Int32 = Swift.Int32()

  /// Default data transfer schedule.
  /// Examples of valid schedules include:
  /// `1st,3rd monday of month 15:30`,
  /// `every wed,fri of jan,jun 13:15`, and
  /// `first sunday of quarter 00:00`.
  public var defaultSchedule: Swift.String = Swift.String()

  /// Specifies whether the data source supports a user defined schedule, or
  /// operates on the default schedule.
  /// When set to `true`, user can override default schedule.
  public var supportsCustomSchedule: Swift.Bool = Swift.Bool()

  /// Data source parameters.
  public var parameters: [DataSourceParameter] = []

  /// Url for the help document for this data source.
  public var helpUrl: Swift.String = Swift.String()

  /// Indicates the type of authorization.
  public var authorizationType: DataSource.AuthorizationType = DataSource.AuthorizationType()

  /// Specifies whether the data source supports automatic data refresh for the
  /// past few days, and how it's supported.
  /// For some data sources, data might not be complete until a few days later,
  /// so it's useful to refresh data automatically.
  public var dataRefreshType: DataSource.DataRefreshType = DataSource.DataRefreshType()

  /// Default data refresh window on days.
  /// Only meaningful when `data_refresh_type` = `SLIDING_WINDOW`.
  public var defaultDataRefreshWindowDays: Swift.Int32 = Swift.Int32()

  /// Disables backfilling and manual run scheduling
  /// for the data source.
  public var manualRunsDisabled: Swift.Bool = Swift.Bool()

  /// The minimum interval for scheduler to schedule runs.
  public var minimumScheduleInterval: GoogleCloudWkt.Duration? = nil

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

  /// The type of authorization needed for this data source.
  public enum AuthorizationType: Codable, Equatable, Sendable {
    /// Type unspecified.
    case unspecified
    /// Use OAuth 2 authorization codes that can be exchanged
    /// for a refresh token on the backend.
    case authorizationCode
    /// Return an authorization code for a given Google+ page that can then be
    /// exchanged for a refresh token on the backend.
    case googlePlusAuthorizationCode
    /// Use First Party OAuth.
    case firstPartyOauth
    /// 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 .authorizationCode: return 1
      case .googlePlusAuthorizationCode: return 2
      case .firstPartyOauth: 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 "AUTHORIZATION_TYPE_UNSPECIFIED"
      case .authorizationCode: return "AUTHORIZATION_CODE"
      case .googlePlusAuthorizationCode: return "GOOGLE_PLUS_AUTHORIZATION_CODE"
      case .firstPartyOauth: return "FIRST_PARTY_OAUTH"
      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:AuthorizationType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "AUTHORIZATION_TYPE_UNSPECIFIED": self = .unspecified
      case "AUTHORIZATION_CODE": self = .authorizationCode
      case "GOOGLE_PLUS_AUTHORIZATION_CODE": self = .googlePlusAuthorizationCode
      case "FIRST_PARTY_OAUTH": self = .firstPartyOauth
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  /// Represents how the data source supports data auto refresh.
  public enum DataRefreshType: Codable, Equatable, Sendable {
    /// The data source won't support data auto refresh, which is default value.
    case unspecified
    /// The data source supports data auto refresh, and runs will be scheduled
    /// for the past few days. Does not allow custom values to be set for each
    /// transfer config.
    case slidingWindow
    /// The data source supports data auto refresh, and runs will be scheduled
    /// for the past few days. Allows custom values to be set for each transfer
    /// config.
    case customSlidingWindow
    /// 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 .slidingWindow: return 1
      case .customSlidingWindow: 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 "DATA_REFRESH_TYPE_UNSPECIFIED"
      case .slidingWindow: return "SLIDING_WINDOW"
      case .customSlidingWindow: return "CUSTOM_SLIDING_WINDOW"
      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:DataRefreshType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "DATA_REFRESH_TYPE_UNSPECIFIED": self = .unspecified
      case "SLIDING_WINDOW": self = .slidingWindow
      case "CUSTOM_SLIDING_WINDOW": self = .customSlidingWindow
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:DataRefreshType/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .slidingWindow
      case 2: self = .customSlidingWindow
      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 .slidingWindow: return try container.encode(1)
      case .customSlidingWindow: 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.bigquery.datatransfer.v1.DataSource"
  }
  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)
  }
}
