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

/// Settings specific to keys that can be used by websites.
public struct WebKeySettings: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Optional. If set to true, it means allowed_domains are not enforced.
  public var allowAllDomains: Swift.Bool = Swift.Bool()

  /// Optional. Domains or subdomains of websites allowed to use the key. All
  /// subdomains of an allowed domain are automatically allowed. A valid domain
  /// requires a host and must not include any path, port, query or fragment.
  /// Examples: 'example.com' or 'subdomain.example.com'
  /// Each key supports a maximum of 250 domains. To use a key on more domains,
  /// set `allow_all_domains` to true. When this is set, you are responsible for
  /// validating the hostname by checking the `token_properties.hostname` field
  /// in each assessment response against your list of allowed domains.
  public var allowedDomains: [Swift.String] = []

  /// Optional. If set to true, the key can be used on AMP (Accelerated Mobile
  /// Pages) websites. This is supported only for the SCORE integration type.
  public var allowAmpTraffic: Swift.Bool = Swift.Bool()

  /// Required. Describes how this key is integrated with the website.
  public var integrationType: WebKeySettings.IntegrationType = WebKeySettings.IntegrationType()

  /// Optional. Settings for the frequency and difficulty at which this key
  /// triggers captcha challenges. This should only be specified for
  /// `IntegrationType` CHECKBOX, INVISIBLE or POLICY_BASED_CHALLENGE.
  public var challengeSecurityPreference: WebKeySettings.ChallengeSecurityPreference =
    WebKeySettings.ChallengeSecurityPreference()

  /// Optional. Challenge settings.
  public var challengeSettings: WebKeySettings.ChallengeSettings? = nil

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

  /// Per-action challenge settings.
  public struct ActionSettings: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. A challenge is triggered if the end-user score is below that
    /// threshold. Value must be between 0 and 1 (inclusive).
    public var scoreThreshold: Swift.Float = Swift.Float()

    /// Initialize a new instance of `ActionSettings`.
    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 = ActionSettings().with { $0.scoreThreshold = ... }
    /// ```
    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.recaptchaenterprise.v1.WebKeySettings.ActionSettings"
    }
    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)
    }
  }

  /// Settings for POLICY_BASED_CHALLENGE keys to control when a challenge is
  /// triggered.
  public struct ChallengeSettings: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. Defines when a challenge is triggered (unless the default
    /// threshold is overridden for the given action, see `action_settings`).
    public var defaultSettings: WebKeySettings.ActionSettings? = nil

    /// Optional. The action to score threshold map.
    /// The action name should be the same as the action name passed in the
    /// `data-action` attribute
    /// (see https://cloud.google.com/recaptcha/docs/actions-website).
    /// Action names are case-insensitive.
    /// There is a maximum of 100 action settings.
    /// An action name has a maximum length of 100.
    public var actionSettings: [Swift.String: WebKeySettings.ActionSettings] = [:]

    /// Initialize a new instance of `ChallengeSettings`.
    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 = ChallengeSettings().with { $0.defaultSettings = ... }
    /// ```
    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.recaptchaenterprise.v1.WebKeySettings.ChallengeSettings"
    }
    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)
    }
  }

  /// Enum that represents the integration types for web keys.
  /// Ensure that applications can handle values not explicitly listed.
  public enum IntegrationType: Codable, Equatable, Sendable {
    /// Default type that indicates this enum hasn't been specified. This is not
    /// a valid IntegrationType, one of the other types must be specified
    /// instead.
    case unspecified
    /// Only used to produce scores. It doesn't display the "I'm not a robot"
    /// checkbox and never shows captcha challenges.
    case score
    /// Displays the "I'm not a robot" checkbox and may show captcha challenges
    /// after it is checked.
    case checkbox
    /// Doesn't display the "I'm not a robot" checkbox, but may show captcha
    /// challenges after risk analysis.
    case invisible
    /// Displays a visual challenge or not depending on the user risk analysis
    /// score.
    case policyBasedChallenge
    /// 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 .score: return 1
      case .checkbox: return 2
      case .invisible: return 3
      case .policyBasedChallenge: return 5
      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 "INTEGRATION_TYPE_UNSPECIFIED"
      case .score: return "SCORE"
      case .checkbox: return "CHECKBOX"
      case .invisible: return "INVISIBLE"
      case .policyBasedChallenge: return "POLICY_BASED_CHALLENGE"
      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:IntegrationType/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "INTEGRATION_TYPE_UNSPECIFIED": self = .unspecified
      case "SCORE": self = .score
      case "CHECKBOX": self = .checkbox
      case "INVISIBLE": self = .invisible
      case "POLICY_BASED_CHALLENGE": self = .policyBasedChallenge
      default: self = .unknownStringValue(stringValue)
      }
    }

    /// Initialize from an integer value.
    ///
    /// If the value is unknown, this initializes to [`unknownIntValue`](doc:IntegrationType/unknownIntValue(_:)).
    public init(intValue: Int) {
      switch intValue {
      case 0: self = .unspecified
      case 1: self = .score
      case 2: self = .checkbox
      case 3: self = .invisible
      case 5: self = .policyBasedChallenge
      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 .score: return try container.encode(1)
      case .checkbox: return try container.encode(2)
      case .invisible: return try container.encode(3)
      case .policyBasedChallenge: return try container.encode(5)
      case .unknownIntValue(let v): return try container.encode(v)
      case .unknownStringValue(let v): return try container.encode(v)
      }
    }
  }

  /// Enum that represents the possible challenge frequency and difficulty
  /// configurations for a web key.
  /// Ensure that applications can handle values not explicitly listed.
  public enum ChallengeSecurityPreference: Codable, Equatable, Sendable {
    /// Default type that indicates this enum hasn't been specified.
    case unspecified
    /// Key tends to show fewer and easier challenges.
    case usability
    /// Key tends to show balanced (in amount and difficulty) challenges.
    case balance
    /// Key tends to show more and harder challenges.
    case security
    /// 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 .usability: return 1
      case .balance: return 2
      case .security: 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 "CHALLENGE_SECURITY_PREFERENCE_UNSPECIFIED"
      case .usability: return "USABILITY"
      case .balance: return "BALANCE"
      case .security: return "SECURITY"
      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:ChallengeSecurityPreference/unknownStringValue(_:)).
    public init(stringValue: Swift.String) {
      switch stringValue {
      case "CHALLENGE_SECURITY_PREFERENCE_UNSPECIFIED": self = .unspecified
      case "USABILITY": self = .usability
      case "BALANCE": self = .balance
      case "SECURITY": self = .security
      default: self = .unknownStringValue(stringValue)
      }
    }

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