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

/// Result in the response to a search request.
///
/// Each result captures details of one entry that matches the search.
public struct SearchCatalogResult: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Type of the search result.
  ///
  /// You can use this field to determine which get method to call to fetch the
  /// full resource.
  public var searchResultType: SearchResultType = SearchResultType()

  /// Sub-type of the search result.
  ///
  /// A dot-delimited full type of the resource. The same type you
  /// specify in the `type` search predicate.
  ///
  /// Examples: `entry.table`, `entry.dataStream`, `tagTemplate`.
  public var searchResultSubtype: Swift.String = Swift.String()

  /// The relative name of the resource in URL format.
  ///
  /// Examples:
  ///
  ///  * `projects/{PROJECT_ID}/locations/{LOCATION_ID}/entryGroups/{ENTRY_GROUP_ID}/entries/{ENTRY_ID}`
  ///  * `projects/{PROJECT_ID}/tagTemplates/{TAG_TEMPLATE_ID}`
  public var relativeResourceName: Swift.String = Swift.String()

  /// The full name of the Google Cloud resource the entry belongs to.
  ///
  /// For more information, see [Full Resource Name]
  /// (/apis/design/resource_names#full_resource_name).
  ///
  /// Example:
  ///
  /// `//bigquery.googleapis.com/projects/PROJECT_ID/datasets/DATASET_ID/tables/TABLE_ID`
  public var linkedResource: Swift.String = Swift.String()

  /// The last modification timestamp of the entry in the source system.
  public var modifyTime: GoogleCloudWkt.Timestamp? = nil

  /// Fully qualified name (FQN) of the resource.
  ///
  /// FQNs take two forms:
  ///
  /// * For non-regionalized resources:
  ///
  ///   `{SYSTEM}:{PROJECT}.{PATH_TO_RESOURCE_SEPARATED_WITH_DOTS}`
  ///
  /// * For regionalized resources:
  ///
  ///   `{SYSTEM}:{PROJECT}.{LOCATION_ID}.{PATH_TO_RESOURCE_SEPARATED_WITH_DOTS}`
  ///
  /// Example for a DPMS table:
  ///
  /// `dataproc_metastore:PROJECT_ID.LOCATION_ID.INSTANCE_ID.DATABASE_ID.TABLE_ID`
  public var fullyQualifiedName: Swift.String = Swift.String()

  /// The display name of the result.
  public var displayName: Swift.String = Swift.String()

  /// Entry description that can consist of several sentences or paragraphs that
  /// describe entry contents.
  public var description: Swift.String = Swift.String()

  /// The source system of the entry. Applicable only when the
  /// `search_result_type` is `ENTRY`.
  public var system: OneOf_System? = nil

  /// Initialize a new instance of `SearchCatalogResult`.
  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 = SearchCatalogResult().with { $0.searchResultType = ... }
  /// ```
  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 searchResultType = "searchResultType"
    case searchResultSubtype = "searchResultSubtype"
    case relativeResourceName = "relativeResourceName"
    case linkedResource = "linkedResource"
    case modifyTime = "modifyTime"
    case integratedSystem = "integratedSystem"
    case userSpecifiedSystem = "userSpecifiedSystem"
    case fullyQualifiedName = "fullyQualifiedName"
    case displayName = "displayName"
    case description = "description"
  }

  public init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    self.searchResultType = try container.decode(SearchResultType.self, forKey: .searchResultType)
    self.searchResultSubtype = try container.decode(Swift.String.self, forKey: .searchResultSubtype)
    self.relativeResourceName = try container.decode(
      Swift.String.self, forKey: .relativeResourceName)
    self.linkedResource = try container.decode(Swift.String.self, forKey: .linkedResource)
    self.modifyTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .modifyTime)
    self.fullyQualifiedName = try container.decode(Swift.String.self, forKey: .fullyQualifiedName)
    self.displayName = try container.decode(Swift.String.self, forKey: .displayName)
    self.description = try container.decode(Swift.String.self, forKey: .description)

    var system: OneOf_System? = nil
    let systemCheckAndSet = {
      if system != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'system'"))
      }
      system = $0
    }
    if let integratedSystem = try container.decodeIfPresent(
      IntegratedSystem.self, forKey: .integratedSystem)
    {
      try systemCheckAndSet(.integratedSystem(integratedSystem))
    }
    if let userSpecifiedSystem = try container.decodeIfPresent(
      Swift.String.self, forKey: .userSpecifiedSystem)
    {
      try systemCheckAndSet(.userSpecifiedSystem(userSpecifiedSystem))
    }
    self.system = system
  }

  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encode(self.searchResultType, forKey: .searchResultType)
    try container.encode(self.searchResultSubtype, forKey: .searchResultSubtype)
    try container.encode(self.relativeResourceName, forKey: .relativeResourceName)
    try container.encode(self.linkedResource, forKey: .linkedResource)
    try container.encode(self.modifyTime, forKey: .modifyTime)
    try container.encode(self.fullyQualifiedName, forKey: .fullyQualifiedName)
    try container.encode(self.displayName, forKey: .displayName)
    try container.encode(self.description, forKey: .description)

    if let choice = self.system {
      switch choice {
      case .integratedSystem(let value):
        try container.encode(value, forKey: .integratedSystem)
      case .userSpecifiedSystem(let value):
        try container.encode(value, forKey: .userSpecifiedSystem)
      }
    }
  }

  /// The source system of the entry. Applicable only when the
  /// `search_result_type` is `ENTRY`.
  public enum OneOf_System: Codable, Equatable, Sendable {
    /// Output only. The source system that Data Catalog automatically integrates
    /// with, such as BigQuery, Cloud Pub/Sub, or Dataproc Metastore.
    case integratedSystem(IntegratedSystem)
    /// Custom source system that you can manually integrate Data Catalog with.
    case userSpecifiedSystem(Swift.String)
  }

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