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

/// Reference object to a data access label.
public struct DataAccessLabelReference: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Output only. The display name of the label.
  /// Data access label and log types's name
  /// will match the display name of the resource.
  /// The asset namespace will match the namespace itself.
  /// The ingestion key value pair will match the key of the tuple.
  public var displayName: Swift.String = Swift.String()

  /// The unique identifier for the label.
  public var label: OneOf_Label? = nil

  /// Initialize a new instance of `DataAccessLabelReference`.
  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 = DataAccessLabelReference().with { $0.dataAccessLabel = ... }
  /// ```
  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 dataAccessLabel = "dataAccessLabel"
    case logType = "logType"
    case assetNamespace = "assetNamespace"
    case ingestionLabel = "ingestionLabel"
    case displayName = "displayName"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.displayName = try container.decode(Swift.String.self, forKey: .displayName)

    var label: OneOf_Label? = nil
    let labelCheckAndSet = {
      if label != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'label'"))
      }
      label = $0
    }
    if let dataAccessLabel = try container.decodeIfPresent(
      Swift.String.self, forKey: .dataAccessLabel)
    {
      try labelCheckAndSet(.dataAccessLabel(dataAccessLabel))
    }
    if let logType = try container.decodeIfPresent(Swift.String.self, forKey: .logType) {
      try labelCheckAndSet(.logType(logType))
    }
    if let assetNamespace = try container.decodeIfPresent(
      Swift.String.self, forKey: .assetNamespace)
    {
      try labelCheckAndSet(.assetNamespace(assetNamespace))
    }
    if let ingestionLabel = try container.decodeIfPresent(
      IngestionLabel?.self, forKey: .ingestionLabel)
    {
      try labelCheckAndSet(.ingestionLabel(ingestionLabel))
    }
    self.label = label
  }

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

    if let choice = self.label {
      switch choice {
      case .dataAccessLabel(let value):
        try container.encode(value, forKey: .dataAccessLabel)
      case .logType(let value):
        try container.encode(value, forKey: .logType)
      case .assetNamespace(let value):
        try container.encode(value, forKey: .assetNamespace)
      case .ingestionLabel(let value):
        try container.encode(value, forKey: .ingestionLabel)
      }
    }
  }

  /// The unique identifier for the label.
  public enum OneOf_Label: Codable, Equatable, Sendable {
    /// The name of the data access label.
    case dataAccessLabel(Swift.String)
    /// The name of the log type.
    case logType(Swift.String)
    /// The asset namespace configured in the forwarder
    /// of the customer's events.
    case assetNamespace(Swift.String)
    /// The ingestion label configured in the forwarder of the customer's events.
    indirect case ingestionLabel(IngestionLabel?)
  }

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