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

#ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_HANDLER_H_
#define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_HANDLER_H_

#include <memory>
#include <optional>
#include <string>

#include "base/functional/callback_forward.h"

class GURL;
class Profile;

// Interface that enables the different kind of notifications to process
// operations coming from the user or decisions made by the underlying
// notification type.
class NotificationHandler {
 public:
  // Type of notifications that a handler can be responsible for.
  // A Java counterpart will be generated for this enum.
  // GENERATED_JAVA_ENUM_PACKAGE: org.chromium.chrome.browser.notifications
  // GENERATED_JAVA_CLASS_NAME_OVERRIDE: NotificationType
  enum class Type {
    WEB_PERSISTENT = 0,
    WEB_NON_PERSISTENT = 1,
    EXTENSION = 2,
    // SEND_TAB_TO_SELF = 3,  // Deprecated.
    TRANSIENT = 4,  // A generic type for any notification that does not outlive
                    // the browser instance and is controlled by a
                    // NotificationDelegate.
    // Deprecated
    // PERMISSION_REQUEST = 5,  // A permission request that is presented to the
    //                          // user via a notification.
    SHARING = 6,
    ANNOUNCEMENT = 7,
    NEARBY_SHARE = 8,
    NOTIFICATIONS_MUTED = 9,
    TAILORED_SECURITY = 10,
    DEFAULT_BROWSER_CHANGED = 11,
    EXTENSION_REQUEST = 12,
    MAX = EXTENSION_REQUEST,
  };

  virtual ~NotificationHandler();

  // Called after a notification has been displayed.
  virtual void OnShow(Profile* profile, const std::string& notification_id);

  // Process notification close events. The |completed_closure| must be invoked
  // on the UI thread once processing of the close event has been finished.
  virtual void OnClose(Profile* profile,
                       const GURL& origin,
                       const std::string& notification_id,
                       bool by_user,
                       base::OnceClosure completed_closure);

  // Process clicks on a notification or its buttons, depending on
  // |action_index|. The |completed_closure| must be invoked on the UI thread
  // once processing of the click event has been finished.
  virtual void OnClick(Profile* profile,
                       const GURL& origin,
                       const std::string& notification_id,
                       const std::optional<int>& action_index,
                       const std::optional<std::u16string>& reply,
                       base::OnceClosure completed_closure);

  // Called when notifications of the given origin have to be disabled. The
  // |notification_id| is included on Android and indicates the notification
  // that led to further notifications being disabled. The |is_suspicious|
  // parameter is used for logging metrics.
  virtual void DisableNotifications(
      Profile* profile,
      const GURL& origin,
      const std::optional<std::string>& notification_id,
      const std::optional<bool>& is_suspicious);

  // Called when the settings page for the given origin has to be opened.
  virtual void OpenSettings(Profile* profile, const GURL& origin);

  // Called when a user clicks to report a notification as safe.
  virtual void ReportNotificationAsSafe(const std::string& notification_id,
                                        const GURL& url,
                                        Profile* profile);

  // Called when a user clicks to report a warned notification as spam.
  virtual void ReportWarnedNotificationAsSpam(
      const std::string& notification_id,
      const GURL& url,
      Profile* profile);

  // Called when a user clicks to report an unwarned notification as spam.
  virtual void ReportUnwarnedNotificationAsSpam(
      const std::string& notification_id,
      const GURL& url,
      Profile* profile);

  // Called when a user taps to show the original contents of a notification
  // after being shown a suspicious notification warning.
  virtual void OnShowOriginalNotification(const GURL& url,
                                          const std::string& notification_id,
                                          Profile* profile);
};

#endif  // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_HANDLER_H_
