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

#if AnswerRecords
  import Foundation
  import GoogleCloudWkt

  /// Represents feedback the customer has about the quality & correctness of a
  /// certain answer in a conversation.
  public struct AnswerFeedback: Codable, Equatable, GoogleCloudWkt._AnyPackable,
    Sendable
  {
    /// The correctness level of the specific answer.
    public var correctnessLevel: AnswerFeedback.CorrectnessLevel = AnswerFeedback.CorrectnessLevel()

    /// Indicates whether the answer/item was clicked by the human agent
    /// or not. Default to false.
    /// For knowledge search and knowledge assist, the answer record is considered
    /// to be clicked if the answer was copied or any URI was clicked.
    public var clicked: Swift.Bool = Swift.Bool()

    /// Time when the answer/item was clicked.
    public var clickTime: GoogleCloudWkt.Timestamp? = nil

    /// Indicates whether the answer/item was displayed to the human
    /// agent in the agent desktop UI. Default to false.
    public var displayed: Swift.Bool = Swift.Bool()

    /// Time when the answer/item was displayed.
    public var displayTime: GoogleCloudWkt.Timestamp? = nil

    /// Normally, detail feedback is provided when answer is not fully correct.
    public var detailFeedback: OneOf_DetailFeedback? = nil

    /// Initialize a new instance of `AnswerFeedback`.
    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 = AnswerFeedback().with { $0.correctnessLevel = ... }
    /// ```
    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 correctnessLevel = "correctnessLevel"
      case agentAssistantDetailFeedback = "agentAssistantDetailFeedback"
      case clicked = "clicked"
      case clickTime = "clickTime"
      case displayed = "displayed"
      case displayTime = "displayTime"
    }

    public init(from decoder: Decoder) throws {
      let container = try decoder.container(keyedBy: CodingKeys.self)
      self.correctnessLevel = try container.decode(
        AnswerFeedback.CorrectnessLevel.self, forKey: .correctnessLevel)
      self.clicked = try container.decode(Swift.Bool.self, forKey: .clicked)
      self.clickTime = try container.decodeIfPresent(
        GoogleCloudWkt.Timestamp.self, forKey: .clickTime)
      self.displayed = try container.decode(Swift.Bool.self, forKey: .displayed)
      self.displayTime = try container.decodeIfPresent(
        GoogleCloudWkt.Timestamp.self, forKey: .displayTime)

      var detailFeedback: OneOf_DetailFeedback? = nil
      let detailFeedbackCheckAndSet = {
        if detailFeedback != nil {
          throw DecodingError.dataCorrupted(
            DecodingError.Context(
              codingPath: decoder.codingPath,
              debugDescription: "Multiple values set for oneof 'detailFeedback'"))
        }
        detailFeedback = $0
      }
      if let agentAssistantDetailFeedback = try container.decodeIfPresent(
        AgentAssistantFeedback?.self, forKey: .agentAssistantDetailFeedback)
      {
        try detailFeedbackCheckAndSet(.agentAssistantDetailFeedback(agentAssistantDetailFeedback))
      }
      self.detailFeedback = detailFeedback
    }

    public func encode(to encoder: Encoder) throws {
      var container = encoder.container(keyedBy: CodingKeys.self)
      try container.encode(self.correctnessLevel, forKey: .correctnessLevel)
      try container.encode(self.clicked, forKey: .clicked)
      try container.encode(self.clickTime, forKey: .clickTime)
      try container.encode(self.displayed, forKey: .displayed)
      try container.encode(self.displayTime, forKey: .displayTime)

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

    /// The correctness level of an answer.
    public enum CorrectnessLevel: Codable, Equatable, Sendable {
      /// Correctness level unspecified.
      case unspecified
      /// Answer is totally wrong.
      case notCorrect
      /// Answer is partially correct.
      case partiallyCorrect
      /// Answer is fully correct.
      case fullyCorrect
      /// 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 .notCorrect: return 1
        case .partiallyCorrect: return 2
        case .fullyCorrect: 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 "CORRECTNESS_LEVEL_UNSPECIFIED"
        case .notCorrect: return "NOT_CORRECT"
        case .partiallyCorrect: return "PARTIALLY_CORRECT"
        case .fullyCorrect: return "FULLY_CORRECT"
        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:CorrectnessLevel/unknownStringValue(_:)).
      public init(stringValue: Swift.String) {
        switch stringValue {
        case "CORRECTNESS_LEVEL_UNSPECIFIED": self = .unspecified
        case "NOT_CORRECT": self = .notCorrect
        case "PARTIALLY_CORRECT": self = .partiallyCorrect
        case "FULLY_CORRECT": self = .fullyCorrect
        default: self = .unknownStringValue(stringValue)
        }
      }

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

    /// Normally, detail feedback is provided when answer is not fully correct.
    public enum OneOf_DetailFeedback: Codable, Equatable, Sendable {
      /// Detail feedback of agent assist suggestions.
      indirect case agentAssistantDetailFeedback(AgentAssistantFeedback?)
    }

    public static var _anyTypeUrl: Swift.String {
      return "type.googleapis.com/google.cloud.dialogflow.v2.AnswerFeedback"
    }
    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)
    }
  }
#endif
