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

/// Guardrail contains a list of checks and balances to keep the agents safe and
/// secure.
public struct Guardrail: Codable, Equatable, GoogleCloudWkt._AnyPackable,
  Sendable
{
  /// Identifier. The unique identifier of the guardrail.
  /// Format:
  /// `projects/{project}/locations/{location}/apps/{app}/guardrails/{guardrail}`
  public var name: Swift.String = Swift.String()

  /// Required. Display name of the guardrail.
  public var displayName: Swift.String = Swift.String()

  /// Optional. Description of the guardrail.
  public var description: Swift.String = Swift.String()

  /// Optional. Whether the guardrail is enabled.
  public var enabled: Swift.Bool = Swift.Bool()

  /// Optional. Action to take when the guardrail is triggered.
  public var action: TriggerAction? = nil

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

  /// Output only. Timestamp when the guardrail was last updated.
  public var updateTime: GoogleCloudWkt.Timestamp? = nil

  /// Etag used to ensure the object hasn't changed during a read-modify-write
  /// operation. If the etag is empty, the update will overwrite any concurrent
  /// changes.
  public var etag: Swift.String = Swift.String()

  /// Guardrail type.
  public var guardrailType: OneOf_GuardrailType? = nil

  /// Initialize a new instance of `Guardrail`.
  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 = Guardrail().with { $0.contentFilter = ... }
  /// ```
  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 contentFilter = "contentFilter"
    case llmPromptSecurity = "llmPromptSecurity"
    case llmPolicy = "llmPolicy"
    case modelSafety = "modelSafety"
    case codeCallback = "codeCallback"
    case name = "name"
    case displayName = "displayName"
    case description = "description"
    case enabled = "enabled"
    case action = "action"
    case createTime = "createTime"
    case updateTime = "updateTime"
    case etag = "etag"
  }

  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.displayName = try container.decode(Swift.String.self, forKey: .displayName)
    self.description = try container.decode(Swift.String.self, forKey: .description)
    self.enabled = try container.decode(Swift.Bool.self, forKey: .enabled)
    self.action = try container.decodeIfPresent(TriggerAction.self, forKey: .action)
    self.createTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .createTime)
    self.updateTime = try container.decodeIfPresent(
      GoogleCloudWkt.Timestamp.self, forKey: .updateTime)
    self.etag = try container.decode(Swift.String.self, forKey: .etag)

    var guardrailType: OneOf_GuardrailType? = nil
    let guardrailTypeCheckAndSet = {
      if guardrailType != nil {
        throw DecodingError.dataCorrupted(
          DecodingError.Context(
            codingPath: decoder.codingPath,
            debugDescription: "Multiple values set for oneof 'guardrailType'"))
      }
      guardrailType = $0
    }
    if let contentFilter = try container.decodeIfPresent(
      Guardrail.ContentFilter?.self, forKey: .contentFilter)
    {
      try guardrailTypeCheckAndSet(.contentFilter(contentFilter))
    }
    if let llmPromptSecurity = try container.decodeIfPresent(
      Guardrail.LlmPromptSecurity?.self, forKey: .llmPromptSecurity)
    {
      try guardrailTypeCheckAndSet(.llmPromptSecurity(llmPromptSecurity))
    }
    if let llmPolicy = try container.decodeIfPresent(Guardrail.LlmPolicy?.self, forKey: .llmPolicy)
    {
      try guardrailTypeCheckAndSet(.llmPolicy(llmPolicy))
    }
    if let modelSafety = try container.decodeIfPresent(
      Guardrail.ModelSafety?.self, forKey: .modelSafety)
    {
      try guardrailTypeCheckAndSet(.modelSafety(modelSafety))
    }
    if let codeCallback = try container.decodeIfPresent(
      Guardrail.CodeCallback?.self, forKey: .codeCallback)
    {
      try guardrailTypeCheckAndSet(.codeCallback(codeCallback))
    }
    self.guardrailType = guardrailType
  }

  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.displayName, forKey: .displayName)
    try container.encode(self.description, forKey: .description)
    try container.encode(self.enabled, forKey: .enabled)
    try container.encode(self.action, forKey: .action)
    try container.encode(self.createTime, forKey: .createTime)
    try container.encode(self.updateTime, forKey: .updateTime)
    try container.encode(self.etag, forKey: .etag)

    if let choice = self.guardrailType {
      switch choice {
      case .contentFilter(let value):
        try container.encode(value, forKey: .contentFilter)
      case .llmPromptSecurity(let value):
        try container.encode(value, forKey: .llmPromptSecurity)
      case .llmPolicy(let value):
        try container.encode(value, forKey: .llmPolicy)
      case .modelSafety(let value):
        try container.encode(value, forKey: .modelSafety)
      case .codeCallback(let value):
        try container.encode(value, forKey: .codeCallback)
      }
    }
  }

  /// Guardrail that bans certain content from being used in the conversation.
  public struct ContentFilter: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. List of banned phrases. Applies to both user inputs and agent
    /// responses.
    public var bannedContents: [Swift.String] = []

    /// Optional. List of banned phrases. Applies only to user inputs.
    public var bannedContentsInUserInput: [Swift.String] = []

    /// Optional. List of banned phrases. Applies only to agent responses.
    public var bannedContentsInAgentResponse: [Swift.String] = []

    /// Required. Match type for the content filter.
    public var matchType: Guardrail.ContentFilter.MatchType = Guardrail.ContentFilter.MatchType()

    /// Optional. If true, diacritics are ignored during matching.
    public var disregardDiacritics: Swift.Bool = Swift.Bool()

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

    /// Match type for the content filter.
    public enum MatchType: Codable, Equatable, Sendable {
      /// Match type is not specified.
      case unspecified
      /// Content is matched for substrings character by character.
      case simpleStringMatch
      /// Content only matches if the pattern found in the text is
      /// surrounded by word delimiters. Banned phrases can also contain word
      /// delimiters.
      case wordBoundaryStringMatch
      /// Content is matched using regular expression syntax.
      case regexpMatch
      /// 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 .simpleStringMatch: return 1
        case .wordBoundaryStringMatch: return 2
        case .regexpMatch: 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 "MATCH_TYPE_UNSPECIFIED"
        case .simpleStringMatch: return "SIMPLE_STRING_MATCH"
        case .wordBoundaryStringMatch: return "WORD_BOUNDARY_STRING_MATCH"
        case .regexpMatch: return "REGEXP_MATCH"
        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:MatchType/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "MATCH_TYPE_UNSPECIFIED": self = .unspecified
        case "SIMPLE_STRING_MATCH": self = .simpleStringMatch
        case "WORD_BOUNDARY_STRING_MATCH": self = .wordBoundaryStringMatch
        case "REGEXP_MATCH": self = .regexpMatch
        default: self = .unknownStringValue(stringValue)
        }
      }

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

  /// Guardrail that blocks the conversation if the input is considered unsafe
  /// based on the LLM classification.
  public struct LlmPromptSecurity: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. Determines the behavior when the guardrail encounters an LLM
    /// error.
    /// - If true: the guardrail is bypassed.
    /// - If false (default): the guardrail triggers/blocks.
    ///
    /// Note: If a custom policy is provided, this field is ignored in favor
    /// of the policy's 'fail_open' configuration.
    public var failOpen: Swift.Bool = Swift.Bool()

    /// Defines the security configuration mode.
    /// The user must choose one of the following configurations.
    public var securityConfig: OneOf_SecurityConfig? = nil

    /// Initialize a new instance of `LlmPromptSecurity`.
    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 = LlmPromptSecurity().with { $0.defaultSettings = ... }
    /// ```
    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 defaultSettings = "defaultSettings"
      case customPolicy = "customPolicy"
      case failOpen = "failOpen"
    }

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

      var securityConfig: OneOf_SecurityConfig? = nil
      let securityConfigCheckAndSet = {
        if securityConfig != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'securityConfig'"))
        }
        securityConfig = $0
      }
      if let defaultSettings = try container.decodeIfPresent(
        Guardrail.LlmPromptSecurity.DefaultSecuritySettings?.self, forKey: .defaultSettings)
      {
        try securityConfigCheckAndSet(.defaultSettings(defaultSettings))
      }
      if let customPolicy = try container.decodeIfPresent(
        Guardrail.LlmPolicy?.self, forKey: .customPolicy)
      {
        try securityConfigCheckAndSet(.customPolicy(customPolicy))
      }
      self.securityConfig = securityConfig
    }

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

      if let choice = self.securityConfig {
        switch choice {
        case .defaultSettings(let value):
          try container.encode(value, forKey: .defaultSettings)
        case .customPolicy(let value):
          try container.encode(value, forKey: .customPolicy)
        }
      }
    }

    /// Configuration for default system security settings.
    public struct DefaultSecuritySettings: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Output only. The default prompt template used by the system.
      /// This field is for display purposes to show the user what prompt
      /// the system uses by default. It is OUTPUT_ONLY.
      public var defaultPromptTemplate: Swift.String = Swift.String()

      /// Initialize a new instance of `DefaultSecuritySettings`.
      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 = DefaultSecuritySettings().with { $0.defaultPromptTemplate = ... }
      /// ```
      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.ces.v1.Guardrail.LlmPromptSecurity.DefaultSecuritySettings"
      }
      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)
      }
    }

    /// Defines the security configuration mode.
    /// The user must choose one of the following configurations.
    public enum OneOf_SecurityConfig: Codable, Equatable, Sendable {
      /// Optional. Use the system's predefined default security settings.
      /// To select this mode, include an empty 'default_settings' message
      /// in the request. The 'default_prompt_template' field within
      /// will be populated by the server in the response.
      indirect case defaultSettings(Guardrail.LlmPromptSecurity.DefaultSecuritySettings?)
      /// Optional. Use a user-defined LlmPolicy to configure the security
      /// guardrail.
      indirect case customPolicy(Guardrail.LlmPolicy?)
    }

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

  /// Guardrail that blocks the conversation if the LLM response is considered
  /// violating the policy based on the LLM classification.
  public struct LlmPolicy: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. When checking this policy, consider the last 'n' messages in
    /// the conversation. When not set a default value of 10 will be used.
    public var maxConversationMessages: Swift.Int32 = Swift.Int32()

    /// Optional. Model settings.
    public var modelSettings: ModelSettings? = nil

    /// Required. Policy prompt.
    public var prompt: Swift.String = Swift.String()

    /// Required. Defines when to apply the policy check during the conversation.
    /// If set to `POLICY_SCOPE_UNSPECIFIED`, the policy will be applied to the
    /// user input. When applying the policy to the agent response, additional
    /// latency will be introduced before the agent can respond.
    public var policyScope: Guardrail.LlmPolicy.PolicyScope = Guardrail.LlmPolicy.PolicyScope()

    /// Optional. If an error occurs during the policy check, fail open and do
    /// not trigger the guardrail.
    public var failOpen: Swift.Bool = Swift.Bool()

    /// Optional. By default, the LLM policy check is bypassed for short
    /// utterances. Enabling this setting applies the policy check to all
    /// utterances, including those that would normally be skipped.
    public var allowShortUtterance: Swift.Bool = Swift.Bool()

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

    /// Defines when to apply the policy check during the conversation.
    public enum PolicyScope: Codable, Equatable, Sendable {
      /// Policy scope is not specified.
      case unspecified
      /// Policy check is triggered on user input.
      case userQuery
      /// Policy check is triggered on agent response. Applying this policy
      /// scope will introduce additional latency before the agent can respond.
      case agentResponse
      /// Policy check is triggered on both user input and agent response.
      /// Applying this policy scope will introduce additional latency before
      /// the agent can respond.
      case userQueryAndAgentResponse
      /// 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 .userQuery: return 1
        case .agentResponse: return 2
        case .userQueryAndAgentResponse: 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 "POLICY_SCOPE_UNSPECIFIED"
        case .userQuery: return "USER_QUERY"
        case .agentResponse: return "AGENT_RESPONSE"
        case .userQueryAndAgentResponse: return "USER_QUERY_AND_AGENT_RESPONSE"
        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:PolicyScope/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "POLICY_SCOPE_UNSPECIFIED": self = .unspecified
        case "USER_QUERY": self = .userQuery
        case "AGENT_RESPONSE": self = .agentResponse
        case "USER_QUERY_AND_AGENT_RESPONSE": self = .userQueryAndAgentResponse
        default: self = .unknownStringValue(stringValue)
        }
      }

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

  /// Model safety settings overrides. When this is set, it will override the
  /// default settings and trigger the guardrail if the response is considered
  /// unsafe.
  public struct ModelSafety: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Required. List of safety settings.
    public var safetySettings: [Guardrail.ModelSafety.SafetySetting] = []

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

    /// Safety setting.
    public struct SafetySetting: Codable, Equatable, GoogleCloudWkt._AnyPackable,
      Sendable
    {
      /// Required. The harm category.
      public var category: Guardrail.ModelSafety.HarmCategory = Guardrail.ModelSafety.HarmCategory()

      /// Required. The harm block threshold.
      public var threshold: Guardrail.ModelSafety.HarmBlockThreshold = Guardrail.ModelSafety
        .HarmBlockThreshold()

      /// Initialize a new instance of `SafetySetting`.
      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 = SafetySetting().with { $0.category = ... }
      /// ```
      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.ces.v1.Guardrail.ModelSafety.SafetySetting"
      }
      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)
      }
    }

    /// Harm category.
    public enum HarmCategory: Codable, Equatable, Sendable {
      /// The harm category is unspecified.
      case unspecified
      /// The harm category is hate speech.
      case hateSpeech
      /// The harm category is dangerous content.
      case dangerousContent
      /// The harm category is harassment.
      case harassment
      /// The harm category is sexually explicit content.
      case sexuallyExplicit
      /// 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 .hateSpeech: return 1
        case .dangerousContent: return 2
        case .harassment: return 3
        case .sexuallyExplicit: 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 "HARM_CATEGORY_UNSPECIFIED"
        case .hateSpeech: return "HARM_CATEGORY_HATE_SPEECH"
        case .dangerousContent: return "HARM_CATEGORY_DANGEROUS_CONTENT"
        case .harassment: return "HARM_CATEGORY_HARASSMENT"
        case .sexuallyExplicit: return "HARM_CATEGORY_SEXUALLY_EXPLICIT"
        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:HarmCategory/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "HARM_CATEGORY_UNSPECIFIED": self = .unspecified
        case "HARM_CATEGORY_HATE_SPEECH": self = .hateSpeech
        case "HARM_CATEGORY_DANGEROUS_CONTENT": self = .dangerousContent
        case "HARM_CATEGORY_HARASSMENT": self = .harassment
        case "HARM_CATEGORY_SEXUALLY_EXPLICIT": self = .sexuallyExplicit
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// Probability based thresholds levels for blocking.
    public enum HarmBlockThreshold: Codable, Equatable, Sendable {
      /// Unspecified harm block threshold.
      case unspecified
      /// Block low threshold and above (i.e. block more).
      case blockLowAndAbove
      /// Block medium threshold and above.
      case blockMediumAndAbove
      /// Block only high threshold (i.e. block less).
      case blockOnlyHigh
      /// Block none.
      case blockNone
      /// Turn off the safety filter.
      case off
      /// 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 .blockLowAndAbove: return 1
        case .blockMediumAndAbove: return 2
        case .blockOnlyHigh: return 3
        case .blockNone: return 4
        case .off: 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 "HARM_BLOCK_THRESHOLD_UNSPECIFIED"
        case .blockLowAndAbove: return "BLOCK_LOW_AND_ABOVE"
        case .blockMediumAndAbove: return "BLOCK_MEDIUM_AND_ABOVE"
        case .blockOnlyHigh: return "BLOCK_ONLY_HIGH"
        case .blockNone: return "BLOCK_NONE"
        case .off: return "OFF"
        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:HarmBlockThreshold/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "HARM_BLOCK_THRESHOLD_UNSPECIFIED": self = .unspecified
        case "BLOCK_LOW_AND_ABOVE": self = .blockLowAndAbove
        case "BLOCK_MEDIUM_AND_ABOVE": self = .blockMediumAndAbove
        case "BLOCK_ONLY_HIGH": self = .blockOnlyHigh
        case "BLOCK_NONE": self = .blockNone
        case "OFF": self = .off
        default: self = .unknownStringValue(stringValue)
        }
      }

      /// Initialize from an integer value.
      ///
      /// If the value is unknown, this initializes to [`unknownIntValue`](doc:HarmBlockThreshold/unknownIntValue(_:)).
      public init(intValue: Int) {
        switch intValue {
        case 0: self = .unspecified
        case 1: self = .blockLowAndAbove
        case 2: self = .blockMediumAndAbove
        case 3: self = .blockOnlyHigh
        case 4: self = .blockNone
        case 5: self = .off
        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 .blockLowAndAbove: return try container.encode(1)
        case .blockMediumAndAbove: return try container.encode(2)
        case .blockOnlyHigh: return try container.encode(3)
        case .blockNone: return try container.encode(4)
        case .off: return try container.encode(5)
        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.ces.v1.Guardrail.ModelSafety"
    }
    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)
    }
  }

  /// Guardrail that blocks the conversation based on the code callbacks
  /// provided.
  public struct CodeCallback: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// Optional. The callback to execute before the agent is called.
    /// Each callback function is expected to return a structure (e.g., a dict or
    /// object) containing at least:
    ///   - 'decision': Either 'OK' or 'TRIGGER'.
    ///   - 'reason': A string explaining the decision.
    /// A 'TRIGGER' decision may halt further processing.
    public var beforeAgentCallback: Callback? = nil

    /// Optional. The callback to execute after the agent is called.
    /// Each callback function is expected to return a structure (e.g., a dict or
    /// object) containing at least:
    ///   - 'decision': Either 'OK' or 'TRIGGER'.
    ///   - 'reason': A string explaining the decision.
    /// A 'TRIGGER' decision may halt further processing.
    public var afterAgentCallback: Callback? = nil

    /// Optional. The callback to execute before the model is called. If there
    /// are multiple calls to the model, the callback will be executed multiple
    /// times. Each callback function is expected to return a structure (e.g., a
    /// dict or object) containing at least:
    ///   - 'decision': Either 'OK' or 'TRIGGER'.
    ///   - 'reason': A string explaining the decision.
    /// A 'TRIGGER' decision may halt further processing.
    public var beforeModelCallback: Callback? = nil

    /// Optional. The callback to execute after the model is called. If there are
    /// multiple calls to the model, the callback will be executed multiple
    /// times. Each callback function is expected to return a structure (e.g., a
    /// dict or object) containing at least:
    ///   - 'decision': Either 'OK' or 'TRIGGER'.
    ///   - 'reason': A string explaining the decision.
    /// A 'TRIGGER' decision may halt further processing.
    public var afterModelCallback: Callback? = nil

    /// Initialize a new instance of `CodeCallback`.
    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 = CodeCallback().with { $0.beforeAgentCallback = ... }
    /// ```
    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.ces.v1.Guardrail.CodeCallback"
    }
    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)
    }
  }

  /// Guardrail type.
  public enum OneOf_GuardrailType: Codable, Equatable, Sendable {
    /// Optional. Guardrail that bans certain content from being used in the
    /// conversation.
    indirect case contentFilter(Guardrail.ContentFilter?)
    /// Optional. Guardrail that blocks the conversation if the prompt is
    /// considered unsafe based on the LLM classification.
    indirect case llmPromptSecurity(Guardrail.LlmPromptSecurity?)
    /// Optional. Guardrail that blocks the conversation if the LLM response is
    /// considered violating the policy based on the LLM classification.
    indirect case llmPolicy(Guardrail.LlmPolicy?)
    /// Optional. Guardrail that blocks the conversation if the LLM response is
    /// considered unsafe based on the model safety settings.
    indirect case modelSafety(Guardrail.ModelSafety?)
    /// Optional. Guardrail that potentially blocks the conversation based on the
    /// result of the callback execution.
    indirect case codeCallback(Guardrail.CodeCallback?)
  }

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