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

/// Filter on job compensation type and amount.
public struct CompensationFilter: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Required. Type of filter.
  public var type: CompensationFilter.FilterType = CompensationFilter.FilterType()

  /// Required. Specify desired `base compensation entry's`
  /// [CompensationInfo.CompensationUnit][google.cloud.talent.v4.CompensationInfo.CompensationUnit].
  ///
  /// [google.cloud.talent.v4.CompensationInfo.CompensationUnit]: <doc:CompensationInfo/CompensationUnit>
  public var units: [CompensationInfo.CompensationUnit] = []

  /// Compensation range.
  public var range: CompensationInfo.CompensationRange? = nil

  /// If set to true, jobs with unspecified compensation range fields are
  /// included.
  public var includeJobsWithUnspecifiedCompensationRange: Swift.Bool = Swift.Bool()

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

  /// Specify the type of filtering.
  public enum FilterType: Codable, Equatable, Sendable {
    /// Filter type unspecified. Position holder, INVALID, should never be used.
    case unspecified
    /// Filter by `base compensation entry's` unit. A job is a match if and
    /// only if the job contains a base CompensationEntry and the base
    /// CompensationEntry's unit matches provided
    /// [units][google.cloud.talent.v4.CompensationFilter.units]. Populate one or
    /// more [units][google.cloud.talent.v4.CompensationFilter.units].
    ///
    /// See
    /// [CompensationInfo.CompensationEntry][google.cloud.talent.v4.CompensationInfo.CompensationEntry]
    /// for definition of base compensation entry.
    ///
    /// [google.cloud.talent.v4.CompensationFilter.units]: <doc:CompensationFilter/units>
    /// [google.cloud.talent.v4.CompensationInfo.CompensationEntry]: <doc:CompensationInfo/CompensationEntry>
    case unitOnly
    /// Filter by `base compensation entry's` unit and amount / range. A job
    /// is a match if and only if the job contains a base CompensationEntry, and
    /// the base entry's unit matches provided
    /// [CompensationUnit][google.cloud.talent.v4.CompensationInfo.CompensationUnit]
    /// and amount or range overlaps with provided
    /// [CompensationRange][google.cloud.talent.v4.CompensationInfo.CompensationRange].
    ///
    /// See
    /// [CompensationInfo.CompensationEntry][google.cloud.talent.v4.CompensationInfo.CompensationEntry]
    /// for definition of base compensation entry.
    ///
    /// Set exactly one [units][google.cloud.talent.v4.CompensationFilter.units]
    /// and populate [range][google.cloud.talent.v4.CompensationFilter.range].
    ///
    /// [google.cloud.talent.v4.CompensationFilter.range]: <doc:CompensationFilter/range>
    /// [google.cloud.talent.v4.CompensationFilter.units]: <doc:CompensationFilter/units>
    /// [google.cloud.talent.v4.CompensationInfo.CompensationEntry]: <doc:CompensationInfo/CompensationEntry>
    /// [google.cloud.talent.v4.CompensationInfo.CompensationRange]: <doc:CompensationInfo/CompensationRange>
    /// [google.cloud.talent.v4.CompensationInfo.CompensationUnit]: <doc:CompensationInfo/CompensationUnit>
    case unitAndAmount
    /// Filter by annualized base compensation amount and `base compensation
    /// entry's` unit. Populate
    /// [range][google.cloud.talent.v4.CompensationFilter.range] and zero or more
    /// [units][google.cloud.talent.v4.CompensationFilter.units].
    ///
    /// [google.cloud.talent.v4.CompensationFilter.range]: <doc:CompensationFilter/range>
    /// [google.cloud.talent.v4.CompensationFilter.units]: <doc:CompensationFilter/units>
    case annualizedBaseAmount
    /// Filter by annualized total compensation amount and `base compensation
    /// entry's` unit . Populate
    /// [range][google.cloud.talent.v4.CompensationFilter.range] and zero or more
    /// [units][google.cloud.talent.v4.CompensationFilter.units].
    ///
    /// [google.cloud.talent.v4.CompensationFilter.range]: <doc:CompensationFilter/range>
    /// [google.cloud.talent.v4.CompensationFilter.units]: <doc:CompensationFilter/units>
    case annualizedTotalAmount
    /// 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 .unitOnly: return 1
      case .unitAndAmount: return 2
      case .annualizedBaseAmount: return 3
      case .annualizedTotalAmount: return 4
      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 "FILTER_TYPE_UNSPECIFIED"
      case .unitOnly: return "UNIT_ONLY"
      case .unitAndAmount: return "UNIT_AND_AMOUNT"
      case .annualizedBaseAmount: return "ANNUALIZED_BASE_AMOUNT"
      case .annualizedTotalAmount: return "ANNUALIZED_TOTAL_AMOUNT"
      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:FilterType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "FILTER_TYPE_UNSPECIFIED": self = .unspecified
      case "UNIT_ONLY": self = .unitOnly
      case "UNIT_AND_AMOUNT": self = .unitAndAmount
      case "ANNUALIZED_BASE_AMOUNT": self = .annualizedBaseAmount
      case "ANNUALIZED_TOTAL_AMOUNT": self = .annualizedTotalAmount
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:FilterType/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .unitOnly
      case 2: self = .unitAndAmount
      case 3: self = .annualizedBaseAmount
      case 4: self = .annualizedTotalAmount
      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 .unitOnly: return try container.encode(1)
      case .unitAndAmount: return try container.encode(2)
      case .annualizedBaseAmount: return try container.encode(3)
      case .annualizedTotalAmount: return try container.encode(4)
      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.talent.v4.CompensationFilter"
  }
  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)
  }
}
