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

/// Report specification for exporting object metadata.
/// Next ID: 4
public struct ObjectMetadataReportOptions: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Metadata fields to be included in the report.
  public var metadataFields: [Swift.String] = []

  /// Filter options for storage systems.
  public var filter: OneOf_Filter? = nil

  /// Options on destination for storage systems.
  public var destinationOptions: OneOf_DestinationOptions? = nil

  /// Initialize a new instance of `ObjectMetadataReportOptions`.
  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 = ObjectMetadataReportOptions().with { $0.metadataFields = ... }
  /// ```
  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 metadataFields = "metadataFields"
    case storageFilters = "storageFilters"
    case storageDestinationOptions = "storageDestinationOptions"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.metadataFields = try container.decode([Swift.String].self, forKey: .metadataFields)

    var filter: OneOf_Filter? = nil
    let filterCheckAndSet = {
      if filter != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'filter'"))
      }
      filter = $0
    }
    if let storageFilters = try container.decodeIfPresent(
      CloudStorageFilters?.self, forKey: .storageFilters)
    {
      try filterCheckAndSet(.storageFilters(storageFilters))
    }
    self.filter = filter

    var destinationOptions: OneOf_DestinationOptions? = nil
    let destinationOptionsCheckAndSet = {
      if destinationOptions != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'destinationOptions'"))
      }
      destinationOptions = $0
    }
    if let storageDestinationOptions = try container.decodeIfPresent(
      CloudStorageDestinationOptions?.self, forKey: .storageDestinationOptions)
    {
      try destinationOptionsCheckAndSet(.storageDestinationOptions(storageDestinationOptions))
    }
    self.destinationOptions = destinationOptions
  }

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

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

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

  /// Filter options for storage systems.
  public enum OneOf_Filter: Codable, Equatable, Sendable {
    /// Cloud Storage as the storage system.
    indirect case storageFilters(CloudStorageFilters?)
  }

  /// Options on destination for storage systems.
  public enum OneOf_DestinationOptions: Codable, Equatable, Sendable {
    /// Cloud Storage as the storage system.
    indirect case storageDestinationOptions(CloudStorageDestinationOptions?)
  }

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