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

/// Tags contain custom metadata and are attached to Data Catalog resources. Tags
/// conform with the specification of their tag template.
///
/// See [Data Catalog
/// IAM](https://cloud.google.com/data-catalog/docs/concepts/iam) for information
/// on the permissions needed to create or view tags.
public struct Tag: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The resource name of the tag in URL format where tag ID is a
  /// system-generated identifier.
  ///
  /// Note: The tag itself might not be stored in the location specified in its
  /// name.
  public var name: Swift.String = Swift.String()

  /// Required. The resource name of the tag template this tag uses. Example:
  ///
  /// `projects/{PROJECT_ID}/locations/{LOCATION}/tagTemplates/{TAG_TEMPLATE_ID}`
  ///
  /// This field cannot be modified after creation.
  public var template: Swift.String = Swift.String()

  /// Output only. The display name of the tag template.
  public var templateDisplayName: Swift.String = Swift.String()

  /// Required. Maps the ID of a tag field to its value and additional
  /// information about that field.
  ///
  /// Tag template defines valid field IDs. A tag
  /// must have at least 1 field and at most 500 fields.
  public var fields: [Swift.String: TagField] = [:]

  /// Output only. Denotes the transfer status of the Tag Template.
  public var dataplexTransferStatus: TagTemplate.DataplexTransferStatus =
    TagTemplate.DataplexTransferStatus()

  /// The scope within the parent resource that this tag is attached to. If not
  /// provided, the tag is attached to the parent resource itself.
  ///
  /// Deleting the scope from the parent resource deletes all tags attached
  /// to that scope.
  ///
  /// These fields cannot be updated after creation.
  public var scope: OneOf_Scope? = nil

  /// Initialize a new instance of `Tag`.
  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 = Tag().with { $0.name = ... }
  /// ```
  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 name = "name"
    case template = "template"
    case templateDisplayName = "templateDisplayName"
    case column = "column"
    case fields = "fields"
    case dataplexTransferStatus = "dataplexTransferStatus"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.name = try container.decode(Swift.String.self, forKey: .name)
    self.template = try container.decode(Swift.String.self, forKey: .template)
    self.templateDisplayName = try container.decode(Swift.String.self, forKey: .templateDisplayName)
    self.fields = try container.decode([Swift.String: TagField].self, forKey: .fields)
    self.dataplexTransferStatus = try container.decode(
      TagTemplate.DataplexTransferStatus.self, forKey: .dataplexTransferStatus)

    var scope: OneOf_Scope? = nil
    let scopeCheckAndSet = {
      if scope != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'scope'"))
      }
      scope = $0
    }
    if let column = try container.decodeIfPresent(Swift.String.self, forKey: .column) {
      try scopeCheckAndSet(.column(column))
    }
    self.scope = scope
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.name, forKey: .name)
    try container.encode(self.template, forKey: .template)
    try container.encode(self.templateDisplayName, forKey: .templateDisplayName)
    try container.encode(self.fields, forKey: .fields)
    try container.encode(self.dataplexTransferStatus, forKey: .dataplexTransferStatus)

    if let choice = self.scope {
      switch choice {
      case .column(let value):
        try container.encode(value, forKey: .column)
      }
    }
  }

  /// The scope within the parent resource that this tag is attached to. If not
  /// provided, the tag is attached to the parent resource itself.
  ///
  /// Deleting the scope from the parent resource deletes all tags attached
  /// to that scope.
  ///
  /// These fields cannot be updated after creation.
  public enum OneOf_Scope: Codable, Equatable, Sendable {
    /// Resources like entry can have schemas associated with them. This scope
    /// allows you to attach tags to an individual column based on that schema.
    ///
    /// To attach a tag to a nested column, separate column names with a dot
    /// (`.`). Example: `column.nested_column`.
    case column(Swift.String)
  }

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