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

/// Metadata type for the long-running operation returned by
/// [RestoreTable][google.bigtable.admin.v2.BigtableTableAdmin.RestoreTable].
///
/// [google.bigtable.admin.v2.BigtableTableAdmin.RestoreTable]: <doc:BigtableTableAdmin/restoreTable(request:)>
public struct RestoreTableMetadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Name of the table being created and restored to.
  public var name: Swift.String = Swift.String()

  /// The type of the restore source.
  public var sourceType: RestoreSourceType = RestoreSourceType()

  /// If exists, the name of the long-running operation that will be used to
  /// track the post-restore optimization process to optimize the performance of
  /// the restored table. The metadata type of the long-running operation is
  /// [OptimizeRestoreTableMetadata][]. The response type is
  /// [Empty][google.protobuf.Empty]. This long-running operation may be
  /// automatically created by the system if applicable after the
  /// RestoreTable long-running operation completes successfully. This operation
  /// may not be created if the table is already optimized or the restore was
  /// not successful.
  public var optimizeTableOperationName: Swift.String = Swift.String()

  /// The progress of the
  /// [RestoreTable][google.bigtable.admin.v2.BigtableTableAdmin.RestoreTable]
  /// operation.
  ///
  /// [google.bigtable.admin.v2.BigtableTableAdmin.RestoreTable]: <doc:BigtableTableAdmin/restoreTable(request:)>
  public var progress: OperationProgress? = nil

  /// Information about the source used to restore the table, as specified by
  /// `source` in
  /// [RestoreTableRequest][google.bigtable.admin.v2.RestoreTableRequest].
  ///
  /// [google.bigtable.admin.v2.RestoreTableRequest]: <doc:RestoreTableRequest>
  public var sourceInfo: OneOf_SourceInfo? = nil

  /// Initialize a new instance of `RestoreTableMetadata`.
  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 = RestoreTableMetadata().with { $0.name = ... }
  /// ```
  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 name = "name"
    case sourceType = "sourceType"
    case backupInfo = "backupInfo"
    case optimizeTableOperationName = "optimizeTableOperationName"
    case progress = "progress"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.sourceType = try container.decode(RestoreSourceType.self, forKey: .sourceType)
    self.optimizeTableOperationName = try container.decode(
      Swift.String.self, forKey: .optimizeTableOperationName)
    self.progress = try container.decodeIfPresent(OperationProgress.self, forKey: .progress)

    var sourceInfo: OneOf_SourceInfo? = nil
    let sourceInfoCheckAndSet = {
      if sourceInfo != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'sourceInfo'"))
      }
      sourceInfo = $0
    }
    if let backupInfo = try container.decodeIfPresent(BackupInfo?.self, forKey: .backupInfo) {
      try sourceInfoCheckAndSet(.backupInfo(backupInfo))
    }
    self.sourceInfo = sourceInfo
  }

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

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

  /// Information about the source used to restore the table, as specified by
  /// `source` in
  /// [RestoreTableRequest][google.bigtable.admin.v2.RestoreTableRequest].
  ///
  /// [google.bigtable.admin.v2.RestoreTableRequest]: <doc:RestoreTableRequest>
  public enum OneOf_SourceInfo: Codable, Equatable, Sendable {
    indirect case backupInfo(BackupInfo?)
  }

  public static var _anyTypeUrl: Swift.String {
    return "type.googleapis.com/google.bigtable.admin.v2.RestoreTableMetadata"
  }
  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)
  }
}
