// 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 InstanceTemplates || Instances || MachineImages || Projects || RegionInstanceTemplates || RegionInstances
  import Foundation
  import GoogleCloudWkt

  /// A metadata key/value entry.
  public struct Metadata: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Specifies a fingerprint for this request, which is essentially a hash of
    /// the metadata's contents and used for optimistic locking. The
    /// fingerprint is initially generated by Compute Engine and changes after
    /// every request to modify or update metadata. You must always provide an
    /// up-to-date fingerprint hash in order to update or change metadata,
    /// otherwise the request will fail with error412 conditionNotMet.
    ///
    /// To see the latest fingerprint, make a get() request to
    /// retrieve the resource.
    public var fingerprint: Foundation.Data? = nil

    /// Array of key/value pairs. The total size of all keys and values must be
    /// less than 512 KB.
    public var items: [Metadata.Items] = []

    /// Output only. [Output Only] Type of the resource. Always compute#metadata
    /// for metadata.
    public var kind: Swift.String? = nil

    /// Initialize a new instance of `Metadata`.
    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 = Metadata().with { $0.fingerprint = ... }
    /// ```
    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 fingerprint = "fingerprint"
      case items = "items"
      case kind = "kind"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      if let s = try container.decodeIfPresent(Swift.String.self, forKey: .fingerprint) {
        guard let v = GoogleCloudWkt._DiscoveryBase64.decode(s) else {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath, debugDescription: "Expected url-safe encoded value")
          )
        }
        self.fingerprint = v
      }
      self.items = try container.decode([Metadata.Items].self, forKey: .items)
      self.kind = try container.decodeIfPresent(Swift.String.self, forKey: .kind)
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      if let v = fingerprint {
        try container.encode(
          GoogleCloudWkt._DiscoveryBase64.encode(v), forKey: .fingerprint
        )
      }
      try container.encode(self.items, forKey: .items)
      try container.encode(self.kind, forKey: .kind)
    }

    /// The message type for the [items][google.cloud.compute.v1.Metadata.items] field.
    ///
    /// [google.cloud.compute.v1.Metadata.items]: <doc:Metadata/Items>
    public struct Items: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Key for the metadata entry. Keys must conform to the following
      /// regexp: [a-zA-Z0-9-_]+, and be less than 128 bytes in length.
      /// This is reflected as part of a URL in the metadata server. Additionally, to
      /// avoid ambiguity, keys must not conflict with any other metadata keys
      /// for the project.
      public var key: Swift.String? = nil

      /// Value for the metadata entry. These are free-form strings, and only
      /// have meaning as interpreted by the image running in the instance. The
      /// only restriction placed on values is that their size must be less than
      /// or equal to 262144 bytes (256 KiB).
      public var value: Swift.String? = nil

      /// Initialize a new instance of `Items`.
      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 = Items().with { $0.key = ... }
      /// ```
      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.compute.v1.Metadata.items"
      }
      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.compute.v1.Metadata"
    }
    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
