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

/// The activity for a findings refinement that is a detection exclusion. The
/// activity is broken down per detector.
public struct DetectionExclusionActivity: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// The activity for the detection exclusion broken down by detector.
  public var detectionExclusionDetectorActivities:
    [DetectionExclusionActivity.DetectionExclusionDetectorActivity] = []

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

  /// The activity for a findings refinement that is a detection exclusion broken
  /// down for one specific detector.
  public struct DetectionExclusionDetectorActivity: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The number of detections for the detector that were excluded by the
    /// detection exclusion.
    public var excludedDetectionCount: Swift.Int64 = Swift.Int64()

    /// The total number of detections found by the detector. This includes both
    /// excluded detections and non-excluded detections.
    public var totalDetectionCount: Swift.Int64 = Swift.Int64()

    public var detectorName: OneOf_DetectorName? = nil

    /// Initialize a new instance of `DetectionExclusionDetectorActivity`.
    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 = DetectionExclusionDetectorActivity().with { $0.curatedRule = ... }
    /// ```
    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 curatedRule = "curatedRule"
      case curatedRuleSet = "curatedRuleSet"
      case rule = "rule"
      case deletedCuratedRuleSet = "deletedCuratedRuleSet"
      case excludedDetectionCount = "excludedDetectionCount"
      case totalDetectionCount = "totalDetectionCount"
    }

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

      var detectorName: OneOf_DetectorName? = nil
      let detectorNameCheckAndSet = {
        if detectorName != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'detectorName'"))
        }
        detectorName = $0
      }
      if let curatedRule = try container.decodeIfPresent(Swift.String.self, forKey: .curatedRule) {
        try detectorNameCheckAndSet(.curatedRule(curatedRule))
      }
      if let curatedRuleSet = try container.decodeIfPresent(
        Swift.String.self, forKey: .curatedRuleSet)
      {
        try detectorNameCheckAndSet(.curatedRuleSet(curatedRuleSet))
      }
      if let rule = try container.decodeIfPresent(Swift.String.self, forKey: .rule) {
        try detectorNameCheckAndSet(.rule(rule))
      }
      if let deletedCuratedRuleSet = try container.decodeIfPresent(
        Swift.String.self, forKey: .deletedCuratedRuleSet)
      {
        try detectorNameCheckAndSet(.deletedCuratedRuleSet(deletedCuratedRuleSet))
      }
      self.detectorName = detectorName
    }

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

      if let choice = self.detectorName {
        switch choice {
        case .curatedRule(let value):
          try container.encode(value, forKey: .curatedRule)
        case .curatedRuleSet(let value):
          try container.encode(value, forKey: .curatedRuleSet)
        case .rule(let value):
          try container.encode(value, forKey: .rule)
        case .deletedCuratedRuleSet(let value):
          try container.encode(value, forKey: .deletedCuratedRuleSet)
        }
      }
    }

    public enum OneOf_DetectorName: Codable, Equatable, Sendable {
      /// Full resource name for the curated rule this activity corresponds to.
      /// Format:
      /// projects/{project}/locations/{location}/instances/{instance}/curatedRules/{rule}
      case curatedRule(Swift.String)
      /// Full resource name for the curated rule set this activity corresponds
      /// to. This field will only be set if the customer has access to the
      /// curated rule set the exclusion is applied to.
      /// Format:
      /// projects/{project}/locations/{location}/instances/{instance}/curatedRuleSetCategories/{curated_rule_set_category}/curatedRuleSets/{curated_rule_set}
      case curatedRuleSet(Swift.String)
      /// Full resource name for the rule this activity corresponds to.
      /// Format:
      /// projects/{project}/locations/{location}/instances/{instance}/rules/{rule}
      case rule(Swift.String)
      /// Full resource name for the deleted curated rule set this activity
      /// corresponds to. This field will only be set if the customer does
      /// not have access to the curated rule set the exclusion is applied to.
      /// Format:
      /// projects/{project}/locations/{location}/instances/{instance}/curatedRuleSetCategories/{curated_rule_set_category}/curatedRuleSets/{curated_rule_set}
      case deletedCuratedRuleSet(Swift.String)
    }

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