// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VISITED_URL_RANKING_PUBLIC_URL_GROUPING_GROUP_SUGGESTIONS_H_
#define COMPONENTS_VISITED_URL_RANKING_PUBLIC_URL_GROUPING_GROUP_SUGGESTIONS_H_

#include <string>

#include "base/functional/callback.h"
#include "base/types/id_type.h"
#include "components/visited_url_ranking/public/url_visit.h"
#include "components/visited_url_ranking/public/visited_url_ranking_service.h"

namespace visited_url_ranking {

// ID to track the suggestion.
using UrlGroupingSuggestionId =
    base::IdType32<class UrlGroupingSuggestionIdTag>;

// Suggestion generated by the service.
struct GroupSuggestion {
  GroupSuggestion();
  ~GroupSuggestion();
  GroupSuggestion(const GroupSuggestion&) = delete;
  GroupSuggestion& operator=(const GroupSuggestion&) = delete;
  GroupSuggestion(GroupSuggestion&&);
  GroupSuggestion& operator=(GroupSuggestion&&);

  GroupSuggestion DeepCopy() const;

  // LINT.IfChange
  // These values are persisted to logs. Entries should not be
  // renumbered and numeric values should never be reused.
  enum class SuggestionReason {
    kUnknown = 0,
    kRecentlyOpened = 1,
    kSwitchedBetween = 2,
    kSimilarSource = 3,
    kSameOrigin = 4,
    kMaxValue = kSameOrigin
  };
  // LINT.ThenChange(/tools/metrics/histograms/visited_url_ranking/enums.xml:GroupSuggesionReason)

  // LINT.IfChange

  // The list of tabs / URLs to suggest, in order of relevance. For the initial
  // prototype, the current tab is always the first entry in the list. This need
  // not be the tab order in the group, if the group is created.
  std::vector<int> tab_ids;

  // The contents of the promo to be shown.
  SuggestionReason suggestion_reason = SuggestionReason::kUnknown;
  std::u16string suggested_name;
  std::string promo_header;
  std::string promo_contents;

  // The ID of the suggestion used to record the user action, or cancel ongoing
  // requests.
  UrlGroupingSuggestionId suggestion_id;

  // LINT.ThenChange(components/visited_url_ranking/public/url_grouping/group_suggestions.cc)
};

struct GroupSuggestions {
  GroupSuggestions();
  ~GroupSuggestions();
  GroupSuggestions(const GroupSuggestions&) = delete;
  GroupSuggestions& operator=(const GroupSuggestions&) = delete;
  GroupSuggestions(GroupSuggestions&&);
  GroupSuggestions& operator=(GroupSuggestions&&);

  GroupSuggestions DeepCopy() const;

  // List of suggestions ordered by priority.
  // Currently the service only supports one suggestion at a time.
  std::vector<GroupSuggestion> suggestions;
};

// The action taken by the user in response to the suggestion.
// GENERATED_JAVA_ENUM_PACKAGE: (
// org.chromium.components.visited_url_ranking.url_grouping)
enum class UserResponse {
  kUnknown = 0,
  kNotShown = 1,
  kAccepted = 2,
  kRejected = 3,
  kIgnored = 4,
};

// The response of the user with metadata like edits made by the user or
// feedback comments.
struct UserResponseMetadata {
  UrlGroupingSuggestionId suggestion_id;
  UserResponse user_response;

  UserResponseMetadata() = default;
  ~UserResponseMetadata() = default;
};

using SuggestionResponseCallback =
    base::OnceCallback<void(UserResponseMetadata)>;

// Struct to cache suggestions and the associated response callback.
struct CachedSuggestions {
  CachedSuggestions();
  ~CachedSuggestions();
  CachedSuggestions(const CachedSuggestions&) = delete;
  CachedSuggestions& operator=(const CachedSuggestions&) = delete;
  CachedSuggestions(CachedSuggestions&&);
  CachedSuggestions& operator=(CachedSuggestions&&);

  GroupSuggestions suggestions;

  // The callback must be called after the UI closes with the user action and
  // the suggestion that was shown.
  SuggestionResponseCallback response_callback;
};

// Returns a string representation of the reason.
const char* GetSuggestionReasonString(GroupSuggestion::SuggestionReason reason);

// LINT.IfChange
// These values are persisted to logs. Entries should not be
// renumbered and numeric values should never be reused.
enum class TabGroupSuggestionThrottleReason {
  kUnknown = 0,
  kOverlappingTabs = 1,
  kOverlappingHosts = 2,
  kGroupNotVisible = 3,
  kMaxValue = kGroupNotVisible
};
// LINT.ThenChange(/tools/metrics/histograms/visited_url_ranking/enums.xml:TabGroupSuggestionThrottleReason)

}  // namespace visited_url_ranking

#endif  // COMPONENTS_VISITED_URL_RANKING_PUBLIC_URL_GROUPING_GROUP_SUGGESTIONS_H_
