#ifndef ASH_ASSISTANT_MODEL_ASSISTANT_RESPONSE_H_
#define ASH_ASSISTANT_MODEL_ASSISTANT_RESPONSE_H_
#include <deque>
#include <memory>
#include <vector>
#include "base/component_export.h"
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/observer_list.h"
#include "chromeos/ash/services/libassistant/public/cpp/assistant_suggestion.h"
namespace base {
class UnguessableToken;
}
namespace ash {
class AssistantResponseObserver;
class AssistantUiElement;
class COMPONENT_EXPORT(ASSISTANT_MODEL) AssistantResponse
: public base::RefCounted<AssistantResponse> {
public:
using AssistantSuggestion = assistant::AssistantSuggestion;
using ProcessingCallback = base::OnceCallback<void(bool)>;
enum class ProcessingState {
kUnprocessed,
kProcessing,
kProcessed,
};
AssistantResponse();
AssistantResponse(const AssistantResponse&) = delete;
AssistantResponse& operator=(const AssistantResponse&) = delete;
void AddObserver(AssistantResponseObserver* observer) const;
void RemoveObserver(AssistantResponseObserver* observer) const;
void AddUiElement(std::unique_ptr<AssistantUiElement> ui_element);
const std::vector<std::unique_ptr<AssistantUiElement>>& GetUiElements() const;
void AddSuggestions(const std::vector<AssistantSuggestion>& suggestions);
const AssistantSuggestion* GetSuggestionById(
const base::UnguessableToken& id) const;
const std::vector<AssistantSuggestion>& GetSuggestions() const;
ProcessingState processing_state() const { return processing_state_; }
void set_processing_state(ProcessingState processing_state) {
processing_state_ = processing_state;
}
bool has_tts() const { return has_tts_; }
void set_has_tts(bool has_tts) { has_tts_ = has_tts; }
void Process(ProcessingCallback callback);
bool ContainsUiElement(const AssistantUiElement* element) const;
private:
void NotifyUiElementAdded(const AssistantUiElement* ui_element);
void NotifySuggestionsAdded(const std::vector<AssistantSuggestion>&);
bool ContainsPendingUiElement(const AssistantUiElement* other) const;
struct PendingUiElement;
class Processor;
friend class base::RefCounted<AssistantResponse>;
~AssistantResponse();
std::deque<std::unique_ptr<PendingUiElement>> pending_ui_elements_;
std::vector<AssistantSuggestion> suggestions_;
ProcessingState processing_state_ = ProcessingState::kUnprocessed;
bool has_tts_ = false;
std::vector<std::unique_ptr<AssistantUiElement>> ui_elements_;
std::unique_ptr<Processor> processor_;
mutable base::ObserverList<AssistantResponseObserver> observers_;
base::WeakPtrFactory<AssistantResponse> weak_factory_{this};
};
}
#endif