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

/// MetadataFeed contains information related to the metadata feed.
public struct MetadataFeed: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The resource name of the metadata feed, in the format
  /// `projects/{project_id_or_number}/locations/{location_id}/metadataFeeds/{metadata_feed_id}`.
  public var name: Swift.String = Swift.String()

  /// Output only. A system-generated, globally unique ID for the metadata job.
  /// If the metadata job is deleted and then re-created with the same name, this
  /// ID is different.
  public var uid: Swift.String = Swift.String()

  /// Required. The scope of the metadata feed.
  /// Only the in scope changes are published.
  public var scope: MetadataFeed.Scope? = nil

  /// Optional. The filters of the metadata feed.
  /// Only the changes that match the filters are published.
  public var filters: MetadataFeed.Filters? = nil

  /// Output only. The time when the feed was created.
  public var createTime: GoogleCloudWkt.Timestamp? = nil

  /// Output only. The time when the feed was updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Optional. User-defined labels.
  public var labels: [Swift.String: Swift.String] = [:]

  /// The endpoint defines the where the metadata feed messages are
  /// published.
  public var endpoint: OneOf_Endpoint? = nil

  /// Initialize a new instance of `MetadataFeed`.
  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 = MetadataFeed().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 uid = "uid"
    case scope = "scope"
    case filters = "filters"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case labels = "labels"
    case pubsubTopic = "pubsubTopic"
  }

  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.uid = try container.decode(Swift.String.self, forKey: .uid)
    self.scope = try container.decodeIfPresent(MetadataFeed.Scope.self, forKey: .scope)
    self.filters = try container.decodeIfPresent(MetadataFeed.Filters.self, forKey: .filters)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.labels = try container.decode([Swift.String: Swift.String].self, forKey: .labels)

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

  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.uid, forKey: .uid)
    try container.encode(self.scope, forKey: .scope)
    try container.encode(self.filters, forKey: .filters)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.labels, forKey: .labels)

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

  /// Scope defines the scope of the metadata feed.
  /// Scopes are exclusive. Only one of the scopes can be specified.
  public struct Scope: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Whether the metadata feed is at the organization-level.
    ///
    /// - If `true`, all changes happened to the entries in the same
    /// organization as the feed are published.
    /// - If `false`, you must specify a list of projects or a list of entry
    /// groups whose entries you want to listen to.
    ///
    /// The default is `false`.
    public var organizationLevel: Swift.Bool = Swift.Bool()

    /// Optional. The projects whose entries you want to listen to.
    /// Must be in the same organization as the feed.
    /// Must be in the format: `projects/{project_id_or_number}`.
    public var projects: [Swift.String] = []

    /// Optional. The entry groups whose entries you want to listen to.
    /// Must be in the format:
    /// `projects/{project_id_or_number}/locations/{location_id}/entryGroups/{entry_group_id}`.
    public var entryGroups: [Swift.String] = []

    /// Initialize a new instance of `Scope`.
    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 = Scope().with { $0.organizationLevel = ... }
    /// ```
    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.dataplex.v1.MetadataFeed.Scope"
    }
    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 defines the type of changes that you want to listen to.
  /// You can have multiple entry type filters and multiple aspect type filters.
  /// All of the entry type filters are OR'ed together.
  /// All of the aspect type filters are OR'ed together.
  /// All of the entry type filters and aspect type filters are AND'ed together.
  public struct Filters: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The entry types that you want to listen to, specified as
    /// relative resource names in the format
    /// `projects/{project_id_or_number}/locations/{location}/entryTypes/{entry_type_id}`.
    /// Only entries that belong to the specified entry types are published.
    public var entryTypes: [Swift.String] = []

    /// Optional. The aspect types that you want to listen to. Depending on how
    /// the aspect is attached to the entry, in the format:
    /// `projects/{project_id_or_number}/locations/{location}/aspectTypes/{aspect_type_id}`.
    public var aspectTypes: [Swift.String] = []

    /// Optional. The type of change that you want to listen to.
    /// If not specified, all changes are published.
    public var changeTypes: [MetadataFeed.Filters.ChangeType] = []

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

    /// The type of change that you want to listen to.
    public enum ChangeType: Codable, Equatable, Sendable {
      /// Unspecified change type. Defaults to UNSPECIFIED.
      case unspecified
      /// The change is a create event.
      case create
      /// The change is an update event.
      case update
      /// The change is a delete event.
      case delete
      /// 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 .create: return 1
        case .update: return 2
        case .delete: return 3
        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 "CHANGE_TYPE_UNSPECIFIED"
        case .create: return "CREATE"
        case .update: return "UPDATE"
        case .delete: return "DELETE"
        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:ChangeType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CHANGE_TYPE_UNSPECIFIED": self = .unspecified
        case "CREATE": self = .create
        case "UPDATE": self = .update
        case "DELETE": self = .delete
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:ChangeType/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .create
        case 2: self = .update
        case 3: self = .delete
        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 .create: return try container.encode(1)
        case .update: return try container.encode(2)
        case .delete: return try container.encode(3)
        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.dataplex.v1.MetadataFeed.Filters"
    }
    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)
    }
  }

  /// The endpoint defines the where the metadata feed messages are
  /// published.
  public enum OneOf_Endpoint: Codable, Equatable, Sendable {
    /// Optional. The pubsub topic that you want the metadata feed messages to
    /// publish to. Please grant Dataplex service account the permission to
    /// publish messages to the topic. The service account is:
    /// service-{PROJECT_NUMBER}@gcp-sa-dataplex.iam.gserviceaccount.com.
    case pubsubTopic(Swift.String)
  }

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