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

/// Configuration of the persistence functionality.
public struct PersistenceConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. Controls whether Persistence features are enabled.
  /// If not provided, the existing value will be used.
  public var persistenceMode: PersistenceConfig.PersistenceMode =
    PersistenceConfig.PersistenceMode()

  /// Optional. Period between RDB snapshots. Snapshots will be attempted every
  /// period starting from the provided snapshot start time. For example, a start
  /// time of 01/01/2033 06:45 and SIX_HOURS snapshot period will do nothing
  /// until 01/01/2033, and then trigger snapshots every day at 06:45, 12:45,
  /// 18:45, and 00:45 the next day, and so on. If not provided,
  /// TWENTY_FOUR_HOURS will be used as default.
  public var rdbSnapshotPeriod: PersistenceConfig.SnapshotPeriod =
    PersistenceConfig.SnapshotPeriod()

  /// Output only. The next time that a snapshot attempt is scheduled to occur.
  public var rdbNextSnapshotTime: GoogleCloudWkt.Timestamp? = nil

  /// Optional. Date and time that the first snapshot was/will be attempted, and
  /// to which future snapshots will be aligned. If not provided, the current
  /// time will be used.
  public var rdbSnapshotStartTime: GoogleCloudWkt.Timestamp? = nil

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

  /// Available Persistence modes.
  public enum PersistenceMode: Codable, Equatable, Sendable {
    /// Not set.
    case unspecified
    /// Persistence is disabled for the instance,
    /// and any existing snapshots are deleted.
    case disabled
    /// RDB based Persistence is enabled.
    case rdb
    /// 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 .disabled: return 1
      case .rdb: return 2
      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 "PERSISTENCE_MODE_UNSPECIFIED"
      case .disabled: return "DISABLED"
      case .rdb: return "RDB"
      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:PersistenceMode/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "PERSISTENCE_MODE_UNSPECIFIED": self = .unspecified
      case "DISABLED": self = .disabled
      case "RDB": self = .rdb
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  /// Available snapshot periods for scheduling.
  public enum SnapshotPeriod: Codable, Equatable, Sendable {
    /// Not set.
    case unspecified
    /// Snapshot every 1 hour.
    case oneHour
    /// Snapshot every 6 hours.
    case sixHours
    /// Snapshot every 12 hours.
    case twelveHours
    /// Snapshot every 24 hours.
    case twentyFourHours
    /// 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 .oneHour: return 3
      case .sixHours: return 4
      case .twelveHours: return 5
      case .twentyFourHours: 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 "SNAPSHOT_PERIOD_UNSPECIFIED"
      case .oneHour: return "ONE_HOUR"
      case .sixHours: return "SIX_HOURS"
      case .twelveHours: return "TWELVE_HOURS"
      case .twentyFourHours: return "TWENTY_FOUR_HOURS"
      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:SnapshotPeriod/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "SNAPSHOT_PERIOD_UNSPECIFIED": self = .unspecified
      case "ONE_HOUR": self = .oneHour
      case "SIX_HOURS": self = .sixHours
      case "TWELVE_HOURS": self = .twelveHours
      case "TWENTY_FOUR_HOURS": self = .twentyFourHours
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:SnapshotPeriod/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 3: self = .oneHour
      case 4: self = .sixHours
      case 5: self = .twelveHours
      case 6: self = .twentyFourHours
      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 .oneHour: return try container.encode(3)
      case .sixHours: return try container.encode(4)
      case .twelveHours: return try container.encode(5)
      case .twentyFourHours: return try container.encode(6)
      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.redis.v1.PersistenceConfig"
  }
  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)
  }
}
