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

/// OS policy assignment is an API resource that is used to
/// apply a set of OS policies to a dynamically targeted group of Compute Engine
/// VM instances.
///
/// An OS policy is used to define the desired state configuration for a
/// Compute Engine VM instance through a set of configuration resources that
/// provide capabilities such as installing or removing software packages, or
/// executing a script.
///
/// For more information, see [OS policy and OS policy
/// assignment](https://cloud.google.com/compute/docs/os-configuration-management/working-with-os-policies).
public struct OSPolicyAssignment: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Resource name.
  ///
  /// Format:
  /// `projects/{project_number}/locations/{location}/osPolicyAssignments/{os_policy_assignment_id}`
  ///
  /// This field is ignored when you create an OS policy assignment.
  public var name: Swift.String = Swift.String()

  /// OS policy assignment description.
  /// Length of the description is limited to 1024 characters.
  public var description: Swift.String = Swift.String()

  /// Required. List of OS policies to be applied to the VMs.
  public var osPolicies: [OSPolicy] = []

  /// Required. Filter to select VMs.
  public var instanceFilter: OSPolicyAssignment.InstanceFilter? = nil

  /// Required. Rollout to deploy the OS policy assignment.
  /// A rollout is triggered in the following situations:
  /// 1) OSPolicyAssignment is created.
  /// 2) OSPolicyAssignment is updated and the update contains changes to one of
  /// the following fields:
  ///    - instance_filter
  ///    - os_policies
  /// 3) OSPolicyAssignment is deleted.
  public var rollout: OSPolicyAssignment.Rollout? = nil

  /// Output only. The assignment revision ID
  /// A new revision is committed whenever a rollout is triggered for a OS policy
  /// assignment
  public var revisionId: Swift.String = Swift.String()

  /// Output only. The timestamp that the revision was created.
  public var revisionCreateTime: GoogleCloudWkt.Timestamp? = nil

  /// The etag for this OS policy assignment.
  /// If this is provided on update, it must match the server's etag.
  public var etag: Swift.String = Swift.String()

  /// Output only. OS policy assignment rollout state
  public var rolloutState: OSPolicyAssignment.RolloutState = OSPolicyAssignment.RolloutState()

  /// Output only. Indicates that this revision has been successfully rolled out
  /// in this zone and new VMs will be assigned OS policies from this revision.
  ///
  /// For a given OS policy assignment, there is only one revision with a value
  /// of `true` for this field.
  public var baseline: Swift.Bool = Swift.Bool()

  /// Output only. Indicates that this revision deletes the OS policy assignment.
  public var deleted: Swift.Bool = Swift.Bool()

  /// Output only. Indicates that reconciliation is in progress for the revision.
  /// This value is `true` when the `rollout_state` is one of:
  /// * IN_PROGRESS
  /// * CANCELLING
  public var reconciling: Swift.Bool = Swift.Bool()

  /// Output only. Server generated unique id for the OS policy assignment
  /// resource.
  public var uid: Swift.String = Swift.String()

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

  /// Message representing label set.
  /// * A label is a key value pair set for a VM.
  /// * A LabelSet is a set of labels.
  /// * Labels within a LabelSet are ANDed. In other words, a LabelSet is
  ///   applicable for a VM only if it matches all the labels in the
  ///   LabelSet.
  /// * Example: A LabelSet with 2 labels: `env=prod` and `type=webserver` will
  ///            only be applicable for those VMs with both labels
  ///            present.
  public struct LabelSet: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Labels are identified by key/value pairs in this map.
    /// A VM should contain all the key/value pairs specified in this
    /// map to be selected.
    public var labels: [Swift.String: Swift.String] = [:]

    /// Initialize a new instance of `LabelSet`.
    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 = LabelSet().with { $0.labels = ... }
    /// ```
    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.osconfig.v1.OSPolicyAssignment.LabelSet"
    }
    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)
    }
  }

  /// Filters to select target VMs for an assignment.
  ///
  /// If more than one filter criteria is specified below, a VM will be selected
  /// if and only if it satisfies all of them.
  public struct InstanceFilter: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Target all VMs in the project. If true, no other criteria is
    /// permitted.
    public var all: Swift.Bool = Swift.Bool()

    /// List of label sets used for VM inclusion.
    ///
    /// If the list has more than one `LabelSet`, the VM is included if any
    /// of the label sets are applicable for the VM.
    public var inclusionLabels: [OSPolicyAssignment.LabelSet] = []

    /// List of label sets used for VM exclusion.
    ///
    /// If the list has more than one label set, the VM is excluded if any
    /// of the label sets are applicable for the VM.
    public var exclusionLabels: [OSPolicyAssignment.LabelSet] = []

    /// List of inventories to select VMs.
    ///
    /// A VM is selected if its inventory data matches at least one of the
    /// following inventories.
    public var inventories: [OSPolicyAssignment.InstanceFilter.Inventory] = []

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

    /// VM inventory details.
    public struct Inventory: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. The OS short name
      public var osShortName: Swift.String = Swift.String()

      /// The OS version
      ///
      /// Prefix matches are supported if asterisk(*) is provided as the
      /// last character. For example, to match all versions with a major
      /// version of `7`, specify the following value for this field `7.*`
      ///
      /// An empty string matches all OS versions.
      public var osVersion: Swift.String = Swift.String()

      /// Initialize a new instance of `Inventory`.
      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 = Inventory().with { $0.osShortName = ... }
      /// ```
      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.osconfig.v1.OSPolicyAssignment.InstanceFilter.Inventory"
      }
      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)
      }
    }

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

  /// Message to configure the rollout at the zonal level for the OS policy
  /// assignment.
  public struct Rollout: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. The maximum number (or percentage) of VMs per zone to disrupt
    /// at any given moment.
    public var disruptionBudget: FixedOrPercent? = nil

    /// Required. This determines the minimum duration of time to wait after the
    /// configuration changes are applied through the current rollout. A
    /// VM continues to count towards the `disruption_budget` at least
    /// until this duration of time has passed after configuration changes are
    /// applied.
    public var minWaitDuration: GoogleCloudWkt.Duration? = nil

    /// Initialize a new instance of `Rollout`.
    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 = Rollout().with { $0.disruptionBudget = ... }
    /// ```
    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.osconfig.v1.OSPolicyAssignment.Rollout"
    }
    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)
    }
  }

  /// OS policy assignment rollout state
  public enum RolloutState: Codable, Equatable, Sendable {
    /// Invalid value
    case unspecified
    /// The rollout is in progress.
    case inProgress
    /// The rollout is being cancelled.
    case cancelling
    /// The rollout is cancelled.
    case cancelled
    /// The rollout has completed successfully.
    case succeeded
    /// 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 .inProgress: return 1
      case .cancelling: return 2
      case .cancelled: return 3
      case .succeeded: 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 "ROLLOUT_STATE_UNSPECIFIED"
      case .inProgress: return "IN_PROGRESS"
      case .cancelling: return "CANCELLING"
      case .cancelled: return "CANCELLED"
      case .succeeded: return "SUCCEEDED"
      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:RolloutState/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "ROLLOUT_STATE_UNSPECIFIED": self = .unspecified
      case "IN_PROGRESS": self = .inProgress
      case "CANCELLING": self = .cancelling
      case "CANCELLED": self = .cancelled
      case "SUCCEEDED": self = .succeeded
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:RolloutState/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .inProgress
      case 2: self = .cancelling
      case 3: self = .cancelled
      case 4: self = .succeeded
      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 .inProgress: return try container.encode(1)
      case .cancelling: return try container.encode(2)
      case .cancelled: return try container.encode(3)
      case .succeeded: 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.osconfig.v1.OSPolicyAssignment"
  }
  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)
  }
}
