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

/// State information for ConfigSync
public struct ConfigSyncState: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The version of ConfigSync deployed
  public var version: ConfigSyncVersion? = nil

  /// Information about the deployment of ConfigSync, including the version
  /// of the various Pods deployed
  public var deploymentState: ConfigSyncDeploymentState? = nil

  /// The state of ConfigSync's process to sync configs to a cluster
  public var syncState: SyncState? = nil

  /// Errors pertaining to the installation of Config Sync.
  public var errors: [ConfigSyncError] = []

  /// The state of the RootSync CRD
  public var rootsyncCrd: ConfigSyncState.CRDState = ConfigSyncState.CRDState()

  /// The state of the Reposync CRD
  public var reposyncCrd: ConfigSyncState.CRDState = ConfigSyncState.CRDState()

  /// The state of CS
  /// This field summarizes the other fields in this message.
  public var state: ConfigSyncState.State = ConfigSyncState.State()

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

  /// CRDState representing the state of a CRD
  public enum CRDState: Codable, Equatable, Sendable {
    /// CRD's state cannot be determined
    case unspecified
    /// CRD is not installed
    case notInstalled
    /// CRD is installed
    case installed
    /// CRD is terminating (i.e., it has been deleted and is cleaning up)
    case terminating
    /// CRD is installing
    case installing
    /// 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 .notInstalled: return 1
      case .installed: return 2
      case .terminating: return 3
      case .installing: 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 "CRD_STATE_UNSPECIFIED"
      case .notInstalled: return "NOT_INSTALLED"
      case .installed: return "INSTALLED"
      case .terminating: return "TERMINATING"
      case .installing: return "INSTALLING"
      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:CRDState/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "CRD_STATE_UNSPECIFIED": self = .unspecified
      case "NOT_INSTALLED": self = .notInstalled
      case "INSTALLED": self = .installed
      case "TERMINATING": self = .terminating
      case "INSTALLING": self = .installing
      default: self = .unknownStringValue(stringValue)
      }
    }

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

  public enum State: Codable, Equatable, Sendable {
    /// CS's state cannot be determined.
    case unspecified
    /// CS is not installed.
    case configSyncNotInstalled
    /// The expected CS version is installed successfully.
    case configSyncInstalled
    /// CS encounters errors.
    case configSyncError
    /// CS is installing or terminating.
    case configSyncPending
    /// 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 .configSyncNotInstalled: return 1
      case .configSyncInstalled: return 2
      case .configSyncError: return 3
      case .configSyncPending: 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 .configSyncNotInstalled: return "CONFIG_SYNC_NOT_INSTALLED"
      case .configSyncInstalled: return "CONFIG_SYNC_INSTALLED"
      case .configSyncError: return "CONFIG_SYNC_ERROR"
      case .configSyncPending: return "CONFIG_SYNC_PENDING"
      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 "CONFIG_SYNC_NOT_INSTALLED": self = .configSyncNotInstalled
      case "CONFIG_SYNC_INSTALLED": self = .configSyncInstalled
      case "CONFIG_SYNC_ERROR": self = .configSyncError
      case "CONFIG_SYNC_PENDING": self = .configSyncPending
      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 = .configSyncNotInstalled
      case 2: self = .configSyncInstalled
      case 3: self = .configSyncError
      case 4: self = .configSyncPending
      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 .configSyncNotInstalled: return try container.encode(1)
      case .configSyncInstalled: return try container.encode(2)
      case .configSyncError: return try container.encode(3)
      case .configSyncPending: 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.gkehub.configmanagement.v1.ConfigSyncState"
  }
  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)
  }
}
