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

/// The configuration of a potential series of Restore operations to be performed
/// against Backups belong to a particular BackupPlan.
public struct RestorePlan: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The full name of the RestorePlan resource.
  /// Format: `projects/*/locations/*/restorePlans/*`.
  public var name: Swift.String = Swift.String()

  /// Output only. Server generated global unique identifier of
  /// [UUID](https://en.wikipedia.org/wiki/Universally_unique_identifier) format.
  public var uid: Swift.String = Swift.String()

  /// Output only. The timestamp when this RestorePlan resource was
  /// created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The timestamp when this RestorePlan resource was last
  /// updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Optional. User specified descriptive string for this RestorePlan.
  public var description: Swift.String = Swift.String()

  /// Required. Immutable. A reference to the
  /// [BackupPlan][google.cloud.gkebackup.v1.BackupPlan] from which Backups may
  /// be used as the source for Restores created via this RestorePlan. Format:
  /// `projects/*/locations/*/backupPlans/*`.
  ///
  /// [google.cloud.gkebackup.v1.BackupPlan]: <doc:BackupPlan>
  public var backupPlan: Swift.String = Swift.String()

  /// Required. Immutable. The target cluster into which Restores created via
  /// this RestorePlan will restore data. NOTE: the cluster's region must be the
  /// same as the RestorePlan. Valid formats:
  ///
  ///   - `projects/*/locations/*/clusters/*`
  ///   - `projects/*/zones/*/clusters/*`
  public var cluster: Swift.String = Swift.String()

  /// Required. Configuration of Restores created via this RestorePlan.
  public var restoreConfig: RestoreConfig? = nil

  /// Optional. A set of custom labels supplied by user.
  public var labels: [Swift.String: Swift.String] = [:]

  /// Output only. `etag` is used for optimistic concurrency control as a way to
  /// help prevent simultaneous updates of a restore from overwriting each other.
  /// It is strongly suggested that systems make use of the `etag` in the
  /// read-modify-write cycle to perform restore updates in order to avoid
  /// race conditions: An `etag` is returned in the response to `GetRestorePlan`,
  /// and systems are expected to put that etag in the request to
  /// `UpdateRestorePlan` or `DeleteRestorePlan` to ensure that their change
  /// will be applied to the same version of the resource.
  public var etag: Swift.String = Swift.String()

  /// Output only. State of the RestorePlan. This State field reflects the
  /// various stages a RestorePlan can be in
  /// during the Create operation.
  public var state: RestorePlan.State = RestorePlan.State()

  /// Output only. Human-readable description of why RestorePlan is in the
  /// current `state`. This field is only meant for human readability and should
  /// not be used programmatically as this field is not guaranteed to be
  /// consistent.
  public var stateReason: Swift.String = Swift.String()

  /// Output only. The fully qualified name of the RestoreChannel to be used to
  /// create a RestorePlan. This field is set only if the `backup_plan` is in a
  /// different project than the RestorePlan. Format:
  /// `projects/*/locations/*/restoreChannels/*`
  public var restoreChannel: Swift.String = Swift.String()

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

  /// State
  public enum State: Codable, Equatable, Sendable {
    /// Default first value for Enums.
    case unspecified
    /// Waiting for cluster state to be RUNNING.
    case clusterPending
    /// The RestorePlan has successfully been created and is ready for Restores.
    case ready
    /// RestorePlan creation has failed.
    case failed
    /// The RestorePlan is in the process of being deleted.
    case deleting
    /// 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 .clusterPending: return 1
      case .ready: return 2
      case .failed: return 3
      case .deleting: 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 "STATE_UNSPECIFIED"
      case .clusterPending: return "CLUSTER_PENDING"
      case .ready: return "READY"
      case .failed: return "FAILED"
      case .deleting: return "DELETING"
      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:State/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "STATE_UNSPECIFIED": self = .unspecified
      case "CLUSTER_PENDING": self = .clusterPending
      case "READY": self = .ready
      case "FAILED": self = .failed
      case "DELETING": self = .deleting
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:State/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .clusterPending
      case 2: self = .ready
      case 3: self = .failed
      case 4: self = .deleting
      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 .clusterPending: return try container.encode(1)
      case .ready: return try container.encode(2)
      case .failed: return try container.encode(3)
      case .deleting: return try container.encode(4)
      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.gkebackup.v1.RestorePlan"
  }
  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)
  }
}
