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

/// Message describing Backup object
public struct Backup: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The name of the backup resource with the format:
  ///  * projects/{project}/locations/{region}/backups/{backup_id}
  /// where the cluster and backup ID segments should satisfy the regex
  /// expression `[a-z]([a-z0-9-]{0,61}[a-z0-9])?`, e.g. 1-63 characters of
  /// lowercase letters, numbers, and dashes, starting with a letter, and ending
  /// with a letter or number. For more details see https://google.aip.dev/122.
  /// The prefix of the backup resource name is the name of the parent
  /// resource:
  ///  * projects/{project}/locations/{region}
  public var name: Swift.String = Swift.String()

  /// User-settable and human-readable display name for the Backup.
  public var displayName: Swift.String = Swift.String()

  /// Output only. The system-generated UID of the resource. The UID is assigned
  /// when the resource is created, and it is retained until it is deleted.
  public var uid: Swift.String = Swift.String()

  /// Output only. Create time stamp
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Update time stamp
  ///
  /// Users should not infer any meaning from this field. Its value is generally
  /// unrelated to the timing of the backup creation operation.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Delete time stamp
  public var deleteTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. Timestamp when the resource finished being created.
  public var createCompletionTime: GoogleCloudWkt.Timestamp? = nil

  /// Labels as key value pairs
  public var labels: [Swift.String: Swift.String] = [:]

  /// Output only. The current state of the backup.
  public var state: Backup.State = Backup.State()

  /// The backup type, which suggests the trigger for the backup.
  public var type: Backup.Type_ = Backup.Type_()

  /// User-provided description of the backup.
  public var description: Swift.String = Swift.String()

  /// Output only. The system-generated UID of the cluster which was used to
  /// create this resource.
  public var clusterUid: Swift.String = Swift.String()

  /// Required. The full resource name of the backup source cluster
  /// (e.g., projects/{project}/locations/{region}/clusters/{cluster_id}).
  public var clusterName: Swift.String = Swift.String()

  /// Output only. Reconciling (https://google.aip.dev/128#reconciliation), if
  /// true, indicates that the service is actively updating the resource. This
  /// can happen due to user-triggered updates or system actions like failover or
  /// maintenance.
  public var reconciling: Swift.Bool = Swift.Bool()

  /// Optional. The encryption config can be specified to encrypt the
  /// backup with a customer-managed encryption key (CMEK). When this field is
  /// not specified, the backup will then use default encryption scheme to
  /// protect the user data.
  public var encryptionConfig: EncryptionConfig? = nil

  /// Output only. The encryption information for the backup.
  public var encryptionInfo: EncryptionInfo? = nil

  /// For Resource freshness validation (https://google.aip.dev/154)
  public var etag: Swift.String = Swift.String()

  /// Annotations to allow client tools to store small amount of arbitrary data.
  /// This is distinct from labels.
  /// https://google.aip.dev/128
  public var annotations: [Swift.String: Swift.String] = [:]

  /// Output only. The size of the backup in bytes.
  public var sizeBytes: Swift.Int64 = Swift.Int64()

  /// Output only. The time at which after the backup is eligible to be garbage
  /// collected. It is the duration specified by the backup's retention policy,
  /// added to the backup's create_time.
  public var expiryTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The QuantityBasedExpiry of the backup, specified by the
  /// backup's retention policy. Once the expiry quantity is over retention, the
  /// backup is eligible to be garbage collected.
  public var expiryQuantity: Backup.QuantityBasedExpiry? = nil

  /// Output only. Reserved for future use.
  public var satisfiesPzs: Swift.Bool = Swift.Bool()

  /// Output only. The database engine major version of the cluster this backup
  /// was created from. Any restored cluster created from this backup will have
  /// the same database version.
  public var databaseVersion: DatabaseVersion = DatabaseVersion()

  /// Optional. Input only. Immutable. Tag keys/values directly bound to this
  /// resource. For example:
  /// ```
  /// "123/environment": "production",
  /// "123/costCenter": "marketing"
  /// ```
  public var tags: [Swift.String: Swift.String] = [:]

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

  /// A backup's position in a quantity-based retention queue, of backups with
  /// the same source cluster and type, with length, retention, specified by the
  /// backup's retention policy.
  /// Once the position is greater than the retention, the backup is eligible to
  /// be garbage collected.
  ///
  /// Example: 5 backups from the same source cluster and type with a
  /// quantity-based retention of 3 and denoted by backup_id (position,
  /// retention).
  ///
  /// Safe: backup_5 (1, 3), backup_4, (2, 3), backup_3 (3, 3).
  /// Awaiting garbage collection: backup_2 (4, 3), backup_1 (5, 3)
  public struct QuantityBasedExpiry: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. The backup's position among its backups with the same source
    /// cluster and type, by descending chronological order create time(i.e.
    /// newest first).
    public var retentionCount: Swift.Int32 = Swift.Int32()

    /// Output only. The length of the quantity-based queue, specified by the
    /// backup's retention policy.
    public var totalRetentionCount: Swift.Int32 = Swift.Int32()

    /// Initialize a new instance of `QuantityBasedExpiry`.
    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 = QuantityBasedExpiry().with { $0.retentionCount = ... }
    /// ```
    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.alloydb.v1.Backup.QuantityBasedExpiry"
    }
    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)
    }
  }

  /// Backup State
  public enum State: Codable, Equatable, Sendable {
    /// The state of the backup is unknown.
    case unspecified
    /// The backup is ready.
    case ready
    /// The backup is creating.
    case creating
    /// The backup failed.
    case failed
    /// The backup is 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 .ready: return 1
      case .creating: 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 .ready: return "READY"
      case .creating: return "CREATING"
      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 "READY": self = .ready
      case "CREATING": self = .creating
      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 = .ready
      case 2: self = .creating
      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 .ready: return try container.encode(1)
      case .creating: 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)
      }
    }
  }

  /// Backup Type
  public enum Type_: Codable, Equatable, Sendable {
    /// Backup Type is unknown.
    case unspecified
    /// ON_DEMAND backups that were triggered by the customer (e.g., not
    /// AUTOMATED).
    case onDemand
    /// AUTOMATED backups triggered by the automated backups scheduler pursuant
    /// to an automated backup policy.
    case automated
    /// CONTINUOUS backups triggered by the automated backups scheduler
    /// due to a continuous backup policy.
    case continuous
    /// 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 .onDemand: return 1
      case .automated: return 2
      case .continuous: 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 "TYPE_UNSPECIFIED"
      case .onDemand: return "ON_DEMAND"
      case .automated: return "AUTOMATED"
      case .continuous: return "CONTINUOUS"
      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:Type_/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "TYPE_UNSPECIFIED": self = .unspecified
      case "ON_DEMAND": self = .onDemand
      case "AUTOMATED": self = .automated
      case "CONTINUOUS": self = .continuous
      default: self = .unknownStringValue(stringValue)
      }
    }

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