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

#ifndef ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_
#define ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_

#include <map>

#include "ash/ash_export.h"
#include "chromeos/components/phonehub/feature_status_provider.h"
#include "chromeos/components/phonehub/notification_manager.h"
#include "chromeos/components/phonehub/tether_controller.h"

namespace chromeos {
namespace phonehub {
class Notification;
class NotificationInteractionHandler;
class PhoneHubManager;
class PhoneModel;
}  // namespace phonehub
}  // namespace chromeos

namespace message_center {
class MessageView;
class Notification;
}  // namespace message_center

namespace ash {

// This controller creates and manages a message_center::Notification for each
// PhoneHub corresponding notification.
class ASH_EXPORT PhoneHubNotificationController
    : public chromeos::phonehub::FeatureStatusProvider::Observer,
      public chromeos::phonehub::NotificationManager::Observer,
      public chromeos::phonehub::TetherController::Observer {
 public:
  PhoneHubNotificationController();
  ~PhoneHubNotificationController() override;
  PhoneHubNotificationController(const PhoneHubNotificationController&) =
      delete;
  PhoneHubNotificationController& operator=(
      const PhoneHubNotificationController&) = delete;

  // Sets the NotifictionManager that provides the underlying PhoneHub
  // notifications.
  void SetManager(chromeos::phonehub::PhoneHubManager* phone_hub_manager);

  const std::u16string GetPhoneName() const;

 private:
  FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
                           ReplyBrieflyDisabled);
  FRIEND_TEST_ALL_PREFIXES(PhoneHubNotificationControllerTest,
                           NotificationHasPhoneName);

  class NotificationDelegate;

  // chromeos::phonehub::FeatureStatusProvider::Observer:
  void OnFeatureStatusChanged() override;

  // chromeos::phonehub::NotificationManager::Observer:
  void OnNotificationsAdded(
      const base::flat_set<int64_t>& notification_ids) override;
  void OnNotificationsUpdated(
      const base::flat_set<int64_t>& notification_ids) override;
  void OnNotificationsRemoved(
      const base::flat_set<int64_t>& notification_ids) override;

  // chromeos::phonehub::TetherController::Observer:
  void OnAttemptConnectionScanFailed() override;
  void OnTetherStatusChanged() override {}

  // Callbacks for user interactions.
  void OpenSettings();
  void DismissNotification(int64_t notification_id);
  void HandleNotificationBodyClick(int64_t notification_id);
  void SendInlineReply(int64_t notification_id,
                       const std::u16string& inline_reply_text);

  // Logs the number of PhoneHub notifications.
  void LogNotificationCount();

  // Shows a Chrome OS notification for the provided phonehub::Notification.
  // If |is_update| is true, this function updates an existing notification;
  // otherwise, a new notification is created.
  void SetNotification(const chromeos::phonehub::Notification* notification,
                       bool is_update);

  // Creates a message_center::Notification from the PhoneHub notification data.
  std::unique_ptr<message_center::Notification> CreateNotification(
      const chromeos::phonehub::Notification* notification,
      const std::string& cros_id,
      NotificationDelegate* delegate,
      bool is_update);
  int GetSystemPriorityForNotification(
      const chromeos::phonehub::Notification* notification,
      bool is_update);

  static std::unique_ptr<message_center::MessageView>
  CreateCustomNotificationView(
      base::WeakPtr<PhoneHubNotificationController> notification_controller,
      const message_center::Notification& notification);

  chromeos::phonehub::NotificationInteractionHandler*
      notification_interaction_handler_ = nullptr;
  chromeos::phonehub::NotificationManager* manager_ = nullptr;
  chromeos::phonehub::FeatureStatusProvider* feature_status_provider_ = nullptr;
  chromeos::phonehub::TetherController* tether_controller_ = nullptr;
  chromeos::phonehub::PhoneModel* phone_model_ = nullptr;
  std::unordered_map<int64_t, std::unique_ptr<NotificationDelegate>>
      notification_map_;

  // A set of notification ids that have been previously shown, even across
  // disconnects. This is needed to prevent pop-ups from reappearing due to a
  // flaky connection. See crbug.com/1150621.
  std::unordered_set<uint64_t> shown_notification_ids_;

  base::WeakPtrFactory<PhoneHubNotificationController> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_SYSTEM_PHONEHUB_PHONE_HUB_NOTIFICATION_CONTROLLER_H_
