// 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 for a Cloud Storage subscription.
public struct CloudStorageConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. User-provided name for the Cloud Storage bucket.
  /// The bucket must be created by the user. The bucket name must be without
  /// any prefix like "gs://". See the [bucket naming
  /// requirements] (https://cloud.google.com/storage/docs/buckets#naming).
  public var bucket: Swift.String = Swift.String()

  /// Optional. User-provided prefix for Cloud Storage filename. See the [object
  /// naming requirements](https://cloud.google.com/storage/docs/objects#naming).
  public var filenamePrefix: Swift.String = Swift.String()

  /// Optional. User-provided suffix for Cloud Storage filename. See the [object
  /// naming requirements](https://cloud.google.com/storage/docs/objects#naming).
  /// Must not end in "/".
  public var filenameSuffix: Swift.String = Swift.String()

  /// Optional. User-provided format string specifying how to represent datetimes
  /// in Cloud Storage filenames. See the [datetime format
  /// guidance](https://cloud.google.com/pubsub/docs/create-cloudstorage-subscription#file_names).
  public var filenameDatetimeFormat: Swift.String = Swift.String()

  /// Optional. File batching settings.
  /// If no max_duration setting is specified, a max_duration of 5 minutes will
  /// be set by default. max_duration is required regardless of whether other
  /// file batching settings are specified.
  ///
  /// The maximum duration that can elapse before a new Cloud Storage file is
  /// created. Min 1 minute, max 10 minutes, default 5 minutes. May not exceed
  /// the subscription's acknowledgement deadline.
  public var maxDuration: GoogleCloudWkt.Duration? = nil

  /// Optional. The maximum bytes that can be written to a Cloud Storage file
  /// before a new file is created. Min 1 KB, max 10 GiB. The max_bytes limit may
  /// be exceeded in cases where messages are larger than the limit.
  public var maxBytes: Swift.Int64 = Swift.Int64()

  /// Optional. The maximum number of messages that can be written to a Cloud
  /// Storage file before a new file is created. Min 1000 messages.
  public var maxMessages: Swift.Int64 = Swift.Int64()

  /// Optional. The service account to use to write to Cloud Storage. The
  /// subscription creator or updater that specifies this field must have
  /// `iam.serviceAccounts.actAs` permission on the service account. If not
  /// specified, the Pub/Sub
  /// [service agent](https://cloud.google.com/iam/docs/service-agents),
  /// service-{project_number}@gcp-sa-pubsub.iam.gserviceaccount.com, is used.
  public var serviceAccountEmail: Swift.String = Swift.String()

  /// Defaults to text format.
  public var outputFormat: OneOf_OutputFormat? = nil

  /// Initialize a new instance of `CloudStorageConfig`.
  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 = CloudStorageConfig().with { $0.textConfig = ... }
  /// ```
  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 textConfig = "textConfig"
    case avroConfig = "avroConfig"
    case bucket = "bucket"
    case filenamePrefix = "filenamePrefix"
    case filenameSuffix = "filenameSuffix"
    case filenameDatetimeFormat = "filenameDatetimeFormat"
    case maxDuration = "maxDuration"
    case maxBytes = "maxBytes"
    case maxMessages = "maxMessages"
    case serviceAccountEmail = "serviceAccountEmail"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.bucket = try container.decode(Swift.String.self, forKey: .bucket)
    self.filenamePrefix = try container.decode(Swift.String.self, forKey: .filenamePrefix)
    self.filenameSuffix = try container.decode(Swift.String.self, forKey: .filenameSuffix)
    self.filenameDatetimeFormat = try container.decode(
      Swift.String.self, forKey: .filenameDatetimeFormat)
    self.maxDuration = try container.decodeIfPresent(
      GoogleCloudWkt.Duration.self, forKey: .maxDuration)
    self.maxBytes = try container.decode(Swift.Int64.self, forKey: .maxBytes)
    self.maxMessages = try container.decode(Swift.Int64.self, forKey: .maxMessages)
    self.serviceAccountEmail = try container.decode(Swift.String.self, forKey: .serviceAccountEmail)

    var outputFormat: OneOf_OutputFormat? = nil
    let outputFormatCheckAndSet = {
      if outputFormat != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'outputFormat'"))
      }
      outputFormat = $0
    }
    if let textConfig = try container.decodeIfPresent(
      CloudStorageConfig.TextConfig?.self, forKey: .textConfig)
    {
      try outputFormatCheckAndSet(.textConfig(textConfig))
    }
    if let avroConfig = try container.decodeIfPresent(
      CloudStorageConfig.AvroConfig?.self, forKey: .avroConfig)
    {
      try outputFormatCheckAndSet(.avroConfig(avroConfig))
    }
    self.outputFormat = outputFormat
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.bucket, forKey: .bucket)
    try container.encode(self.filenamePrefix, forKey: .filenamePrefix)
    try container.encode(self.filenameSuffix, forKey: .filenameSuffix)
    try container.encode(self.filenameDatetimeFormat, forKey: .filenameDatetimeFormat)
    try container.encode(self.maxDuration, forKey: .maxDuration)
    try container.encode(self.maxBytes, forKey: .maxBytes)
    try container.encode(self.maxMessages, forKey: .maxMessages)
    try container.encode(self.serviceAccountEmail, forKey: .serviceAccountEmail)

    if let choice = self.outputFormat {
      switch choice {
      case .textConfig(let value):
        try container.encode(value, forKey: .textConfig)
      case .avroConfig(let value):
        try container.encode(value, forKey: .avroConfig)
      }
    }
  }

  /// Configuration for writing message data in text format.
  /// Message payloads will be written to files as raw text, separated by a
  /// newline.
  public struct TextConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Initialize a new instance of `TextConfig`.
    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 = TextConfig().with { $0.<placeholder> = ... }
    /// ```
    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.bigquery.analyticshub.v1.CloudStorageConfig.TextConfig"
    }
    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)
    }
  }

  /// Configuration for writing message data in Avro format.
  /// Message payloads and metadata will be written to files as an Avro binary.
  public struct AvroConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. When true, write the subscription name, message_id,
    /// publish_time, attributes, and ordering_key as additional fields in the
    /// output. The subscription name, message_id, and publish_time fields are
    /// put in their own fields while all other message properties other than
    /// data (for example, an ordering_key, if present) are added as entries in
    /// the attributes map.
    public var writeMetadata: Swift.Bool = Swift.Bool()

    /// Optional. When true, the output Cloud Storage file will be serialized
    /// using the topic schema, if it exists.
    public var useTopicSchema: Swift.Bool = Swift.Bool()

    /// Initialize a new instance of `AvroConfig`.
    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 = AvroConfig().with { $0.writeMetadata = ... }
    /// ```
    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.bigquery.analyticshub.v1.CloudStorageConfig.AvroConfig"
    }
    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)
    }
  }

  /// Defaults to text format.
  public enum OneOf_OutputFormat: Codable, Equatable, Sendable {
    /// Optional. If set, message data will be written to Cloud Storage in text
    /// format.
    indirect case textConfig(CloudStorageConfig.TextConfig?)
    /// Optional. If set, message data will be written to Cloud Storage in Avro
    /// format.
    indirect case avroConfig(CloudStorageConfig.AvroConfig?)
  }

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