#pragma once

#include <functional>

#include <QByteArray>
#include <QString>

#include "core/entitlement.hpp"

class QObject;
class QWidget;

namespace smartcut::gui {

class LicenseManager {
 public:
  using RefreshCompletion = std::function<void(bool updated, const QString& message)>;

  LicenseManager();

  void reload();
  void show_dialog(QWidget* parent);
  void refresh_online_async(QObject* context, RefreshCompletion completion = {});
  [[nodiscard]] bool paid() const { return result_.paid(); }
  [[nodiscard]] bool online_available() const;
  [[nodiscard]] const core::EntitlementResult& result() const { return result_; }
  [[nodiscard]] QString edition_suffix() const;
  [[nodiscard]] QString status_text() const;

 private:
  QString default_path() const;
  QString configured_path() const;
  bool install_file(const QString& source, QWidget* parent);
  bool install_token(const QByteArray& token, QString& error);

  core::EntitlementResult result_;
  QString active_path_;
};

}  // namespace smartcut::gui
