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

/// Specifies the cluster auto-delete schedule configuration.
public struct LifecycleConfig: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. The duration to keep the cluster alive while idling (when no jobs
  /// are running). Passing this threshold will cause the cluster to be
  /// deleted. Minimum value is 5 minutes; maximum value is 14 days (see JSON
  /// representation of
  /// [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json)).
  public var idleDeleteTtl: GoogleCloudWkt.Duration? = nil

  /// Optional. The duration to keep the cluster started while idling (when no
  /// jobs are running). Passing this threshold will cause the cluster to be
  /// stopped. Minimum value is 5 minutes; maximum value is 14 days (see JSON
  /// representation of
  /// [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json)).
  public var idleStopTtl: GoogleCloudWkt.Duration? = nil

  /// Output only. The time when cluster became idle (most recent job finished)
  /// and became eligible for deletion due to idleness (see JSON representation
  /// of
  /// [Timestamp](https://developers.google.com/protocol-buffers/docs/proto3#json)).
  public var idleStartTime: GoogleCloudWkt.Timestamp? = nil

  /// Either the exact time the cluster should be deleted at or
  /// the cluster maximum age.
  public var ttl: OneOf_Ttl? = nil

  /// Either the exact time the cluster should be stopped at or
  /// the cluster maximum age.
  public var stopTtl: OneOf_StopTtl? = nil

  /// Initialize a new instance of `LifecycleConfig`.
  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 = LifecycleConfig().with { $0.idleDeleteTtl = ... }
  /// ```
  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 idleDeleteTtl = "idleDeleteTtl"
    case autoDeleteTime = "autoDeleteTime"
    case autoDeleteTtl = "autoDeleteTtl"
    case idleStopTtl = "idleStopTtl"
    case autoStopTime = "autoStopTime"
    case autoStopTtl = "autoStopTtl"
    case idleStartTime = "idleStartTime"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.idleDeleteTtl = try container.decodeIfPresent(
      GoogleCloudWkt.Duration.self, forKey: .idleDeleteTtl)
    self.idleStopTtl = try container.decodeIfPresent(
      GoogleCloudWkt.Duration.self, forKey: .idleStopTtl)
    self.idleStartTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .idleStartTime)

    var ttl: OneOf_Ttl? = nil
    let ttlCheckAndSet = {
      if ttl != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath, debugDescription: "Multiple values set for oneof 'ttl'")
        )
      }
      ttl = $0
    }
    if let autoDeleteTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp?.self, forKey: .autoDeleteTime)
    {
      try ttlCheckAndSet(.autoDeleteTime(autoDeleteTime))
    }
    if let autoDeleteTtl = try container.decodeIfPresent(
      GoogleCloudWkt.Duration?.self, forKey: .autoDeleteTtl)
    {
      try ttlCheckAndSet(.autoDeleteTtl(autoDeleteTtl))
    }
    self.ttl = ttl

    var stopTtl: OneOf_StopTtl? = nil
    let stopTtlCheckAndSet = {
      if stopTtl != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'stopTtl'"))
      }
      stopTtl = $0
    }
    if let autoStopTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp?.self, forKey: .autoStopTime)
    {
      try stopTtlCheckAndSet(.autoStopTime(autoStopTime))
    }
    if let autoStopTtl = try container.decodeIfPresent(
      GoogleCloudWkt.Duration?.self, forKey: .autoStopTtl)
    {
      try stopTtlCheckAndSet(.autoStopTtl(autoStopTtl))
    }
    self.stopTtl = stopTtl
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.idleDeleteTtl, forKey: .idleDeleteTtl)
    try container.encode(self.idleStopTtl, forKey: .idleStopTtl)
    try container.encode(self.idleStartTime, forKey: .idleStartTime)

    if let choice = self.ttl {
      switch choice {
      case .autoDeleteTime(let value):
        try container.encode(value, forKey: .autoDeleteTime)
      case .autoDeleteTtl(let value):
        try container.encode(value, forKey: .autoDeleteTtl)
      }
    }

    if let choice = self.stopTtl {
      switch choice {
      case .autoStopTime(let value):
        try container.encode(value, forKey: .autoStopTime)
      case .autoStopTtl(let value):
        try container.encode(value, forKey: .autoStopTtl)
      }
    }
  }

  /// Either the exact time the cluster should be deleted at or
  /// the cluster maximum age.
  public enum OneOf_Ttl: Codable, Equatable, Sendable {
    /// Optional. The time when cluster will be auto-deleted (see JSON
    /// representation of
    /// [Timestamp](https://developers.google.com/protocol-buffers/docs/proto3#json)).
    indirect case autoDeleteTime(GoogleCloudWkt.Timestamp?)
    /// Optional. The lifetime duration of cluster. The cluster will be
    /// auto-deleted at the end of this period. Minimum value is 10 minutes;
    /// maximum value is 14 days (see JSON representation of
    /// [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json)).
    indirect case autoDeleteTtl(GoogleCloudWkt.Duration?)
  }

  /// Either the exact time the cluster should be stopped at or
  /// the cluster maximum age.
  public enum OneOf_StopTtl: Codable, Equatable, Sendable {
    /// Optional. The time when cluster will be auto-stopped (see JSON
    /// representation of
    /// [Timestamp](https://developers.google.com/protocol-buffers/docs/proto3#json)).
    indirect case autoStopTime(GoogleCloudWkt.Timestamp?)
    /// Optional. The lifetime duration of the cluster. The cluster will be
    /// auto-stopped at the end of this period, calculated from the time of
    /// submission of the create or update cluster request. Minimum value is 10
    /// minutes; maximum value is 14 days (see JSON representation of
    /// [Duration](https://developers.google.com/protocol-buffers/docs/proto3#json)).
    indirect case autoStopTtl(GoogleCloudWkt.Duration?)
  }

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