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

#if SqlBackupsService
  import Foundation
  import GoogleCloudWkt
  import GoogleType

  /// A backup resource.
  public struct Backup: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Output only. The resource name of the backup.
    /// Format: projects/{project}/backups/{backup}.
    public var name: Swift.String = Swift.String()

    /// Output only. This is always `sql#backup`.
    public var kind: Swift.String = Swift.String()

    /// Output only. The URI of this resource.
    public var selfLink: Swift.String = Swift.String()

    /// Output only. The type of this backup. The type can be "AUTOMATED",
    /// "ON_DEMAND" or “FINAL”.
    public var type: Backup.SqlBackupType = Backup.SqlBackupType()

    /// The description of this backup.
    public var description: Swift.String = Swift.String()

    /// The name of the source database instance.
    public var instance: Swift.String = Swift.String()

    /// The storage location of the backups. The location can be multi-regional.
    public var location: Swift.String = Swift.String()

    /// Output only. This output contains the following values:
    /// start_time: All database writes up to this time are available.
    /// end_time: Any database writes after this time aren't available.
    public var backupInterval: GoogleType.Interval? = nil

    /// Output only. The status of this backup.
    public var state: Backup.SqlBackupState = Backup.SqlBackupState()

    /// Output only. Information about why the backup operation fails (for example,
    /// when the backup state fails).
    public var error: OperationError? = nil

    /// Output only. This output contains the encryption configuration for a backup
    /// and the resource name of the KMS key for disk encryption.
    public var kmsKey: Swift.String = Swift.String()

    /// Output only. This output contains the encryption status for a backup and
    /// the version of the KMS key that's used to encrypt the Cloud SQL instance.
    public var kmsKeyVersion: Swift.String = Swift.String()

    /// Output only. Specifies the kind of backup, PHYSICAL or DEFAULT_SNAPSHOT.
    public var backupKind: SqlBackupKind = SqlBackupKind()

    /// Output only. This output contains a backup time zone. If a Cloud SQL for
    /// SQL Server instance has a different time zone from the backup's time zone,
    /// then the restore to the instance doesn't happen.
    public var timeZone: Swift.String = Swift.String()

    /// Output only. The database version of the instance of at the time this
    /// backup was made.
    public var databaseVersion: SqlDatabaseVersion = SqlDatabaseVersion()

    /// Output only. The maximum chargeable bytes for the backup.
    public var maxChargeableBytes: Swift.Int64? = nil

    /// Optional. Output only. Timestamp in UTC of when the instance associated
    /// with this backup is deleted.
    public var instanceDeletionTime: GoogleCloudWkt.Timestamp? = nil

    /// Optional. Output only. The instance setting of the source instance that's
    /// associated with this backup.
    public var instanceSettings: DatabaseInstance? = nil

    /// Output only. The mapping to backup run resource used for IAM validations.
    public var backupRun: Swift.String = Swift.String()

    /// Output only. This status indicates whether the backup satisfies PZS.
    ///
    /// The status is reserved for future use.
    public var satisfiesPzs: GoogleCloudWkt.BoolValue? = nil

    /// Output only. This status indicates whether the backup satisfies PZI.
    ///
    /// The status is reserved for future use.
    public var satisfiesPzi: GoogleCloudWkt.BoolValue? = nil

    public var expiration: OneOf_Expiration? = nil

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

    private enum CodingKeys: Swift.String, CodingKey {
      case name = "name"
      case kind = "kind"
      case selfLink = "selfLink"
      case type = "type"
      case description = "description"
      case instance = "instance"
      case location = "location"
      case backupInterval = "backupInterval"
      case state = "state"
      case error = "error"
      case kmsKey = "kmsKey"
      case kmsKeyVersion = "kmsKeyVersion"
      case backupKind = "backupKind"
      case timeZone = "timeZone"
      case ttlDays = "ttlDays"
      case expiryTime = "expiryTime"
      case databaseVersion = "databaseVersion"
      case maxChargeableBytes = "maxChargeableBytes"
      case instanceDeletionTime = "instanceDeletionTime"
      case instanceSettings = "instanceSettings"
      case backupRun = "backupRun"
      case satisfiesPzs = "satisfiesPzs"
      case satisfiesPzi = "satisfiesPzi"
    }

    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.kind = try container.decode(Swift.String.self, forKey: .kind)
      self.selfLink = try container.decode(Swift.String.self, forKey: .selfLink)
      self.type = try container.decode(Backup.SqlBackupType.self, forKey: .type)
      self.description = try container.decode(Swift.String.self, forKey: .description)
      self.instance = try container.decode(Swift.String.self, forKey: .instance)
      self.location = try container.decode(Swift.String.self, forKey: .location)
      self.backupInterval = try container.decodeIfPresent(
        GoogleType.Interval.self, forKey: .backupInterval)
      self.state = try container.decode(Backup.SqlBackupState.self, forKey: .state)
      self.error = try container.decodeIfPresent(OperationError.self, forKey: .error)
      self.kmsKey = try container.decode(Swift.String.self, forKey: .kmsKey)
      self.kmsKeyVersion = try container.decode(Swift.String.self, forKey: .kmsKeyVersion)
      self.backupKind = try container.decode(SqlBackupKind.self, forKey: .backupKind)
      self.timeZone = try container.decode(Swift.String.self, forKey: .timeZone)
      self.databaseVersion = try container.decode(SqlDatabaseVersion.self, forKey: .databaseVersion)
      self.maxChargeableBytes = try container.decodeIfPresent(
        Swift.Int64.self, forKey: .maxChargeableBytes)
      self.instanceDeletionTime = try container.decodeIfPresent(
        GoogleCloudWkt.Timestamp.self, forKey: .instanceDeletionTime)
      self.instanceSettings = try container.decodeIfPresent(
        DatabaseInstance.self, forKey: .instanceSettings)
      self.backupRun = try container.decode(Swift.String.self, forKey: .backupRun)
      self.satisfiesPzs = try container.decodeIfPresent(
        GoogleCloudWkt.BoolValue.self, forKey: .satisfiesPzs)
      self.satisfiesPzi = try container.decodeIfPresent(
        GoogleCloudWkt.BoolValue.self, forKey: .satisfiesPzi)

      var expiration: OneOf_Expiration? = nil
      let expirationCheckAndSet = {
        if expiration != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'expiration'"))
        }
        expiration = $0
      }
      if let ttlDays = try container.decodeIfPresent(Swift.Int64.self, forKey: .ttlDays) {
        try expirationCheckAndSet(.ttlDays(ttlDays))
      }
      if let expiryTime = try container.decodeIfPresent(
        GoogleCloudWkt.Timestamp?.self, forKey: .expiryTime)
      {
        try expirationCheckAndSet(.expiryTime(expiryTime))
      }
      self.expiration = expiration
    }

    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.kind, forKey: .kind)
      try container.encode(self.selfLink, forKey: .selfLink)
      try container.encode(self.type, forKey: .type)
      try container.encode(self.description, forKey: .description)
      try container.encode(self.instance, forKey: .instance)
      try container.encode(self.location, forKey: .location)
      try container.encode(self.backupInterval, forKey: .backupInterval)
      try container.encode(self.state, forKey: .state)
      try container.encode(self.error, forKey: .error)
      try container.encode(self.kmsKey, forKey: .kmsKey)
      try container.encode(self.kmsKeyVersion, forKey: .kmsKeyVersion)
      try container.encode(self.backupKind, forKey: .backupKind)
      try container.encode(self.timeZone, forKey: .timeZone)
      try container.encode(self.databaseVersion, forKey: .databaseVersion)
      try container.encode(self.maxChargeableBytes, forKey: .maxChargeableBytes)
      try container.encode(self.instanceDeletionTime, forKey: .instanceDeletionTime)
      try container.encode(self.instanceSettings, forKey: .instanceSettings)
      try container.encode(self.backupRun, forKey: .backupRun)
      try container.encode(self.satisfiesPzs, forKey: .satisfiesPzs)
      try container.encode(self.satisfiesPzi, forKey: .satisfiesPzi)

      if let choice = self.expiration {
        switch choice {
        case .ttlDays(let value):
          try container.encode(value, forKey: .ttlDays)
        case .expiryTime(let value):
          try container.encode(value, forKey: .expiryTime)
        }
      }
    }

    /// The backup type.
    public enum SqlBackupType: Codable, Equatable, Sendable {
      /// This is an unknown backup type.
      case unspecified
      /// The backup schedule triggers a backup automatically.
      case automated
      /// The user triggers a backup manually.
      case onDemand
      /// The backup created when instance is deleted.
      case `final`
      /// 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 .automated: return 1
        case .onDemand: return 2
        case .`final`: 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 "SQL_BACKUP_TYPE_UNSPECIFIED"
        case .automated: return "AUTOMATED"
        case .onDemand: return "ON_DEMAND"
        case .`final`: return "FINAL"
        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:SqlBackupType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "SQL_BACKUP_TYPE_UNSPECIFIED": self = .unspecified
        case "AUTOMATED": self = .automated
        case "ON_DEMAND": self = .onDemand
        case "FINAL": self = .`final`
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// The backup's state
    public enum SqlBackupState: Codable, Equatable, Sendable {
      /// The state of the backup is unknown.
      case unspecified
      /// The backup that's added to a queue.
      case enqueued
      /// The backup is in progress.
      case running
      /// The backup failed.
      case failed
      /// The backup is successful.
      case successful
      /// The backup is being deleted.
      case deleting
      /// Deletion of the backup failed.
      case deletionFailed
      /// 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 .enqueued: return 1
        case .running: return 2
        case .failed: return 3
        case .successful: return 4
        case .deleting: return 5
        case .deletionFailed: return 6
        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 "SQL_BACKUP_STATE_UNSPECIFIED"
        case .enqueued: return "ENQUEUED"
        case .running: return "RUNNING"
        case .failed: return "FAILED"
        case .successful: return "SUCCESSFUL"
        case .deleting: return "DELETING"
        case .deletionFailed: return "DELETION_FAILED"
        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:SqlBackupState/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "SQL_BACKUP_STATE_UNSPECIFIED": self = .unspecified
        case "ENQUEUED": self = .enqueued
        case "RUNNING": self = .running
        case "FAILED": self = .failed
        case "SUCCESSFUL": self = .successful
        case "DELETING": self = .deleting
        case "DELETION_FAILED": self = .deletionFailed
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:SqlBackupState/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .enqueued
        case 2: self = .running
        case 3: self = .failed
        case 4: self = .successful
        case 5: self = .deleting
        case 6: self = .deletionFailed
        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 .enqueued: return try container.encode(1)
        case .running: return try container.encode(2)
        case .failed: return try container.encode(3)
        case .successful: return try container.encode(4)
        case .deleting: return try container.encode(5)
        case .deletionFailed: return try container.encode(6)
        case .unknownIntValue(let v): return try container.encode(v)
        case .unknownStringValue(let v): return try container.encode(v)
        }
      }
    }

    public enum OneOf_Expiration: Codable, Equatable, Sendable {
      /// Input only. The time-to-live (TTL) interval for this resource (in days).
      /// For example: ttlDays:7, means 7 days from the current time. The
      /// expiration time can't exceed 365 days from the time that the backup is
      /// created.
      case ttlDays(Swift.Int64)
      /// Backup expiration time.
      /// A UTC timestamp of when this backup expired.
      indirect case expiryTime(GoogleCloudWkt.Timestamp?)
    }

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