#pragma once

#include <eedb/widgets/AuthPage.hpp>

#include <memory>

namespace Wt::Auth {
class AbstractUserDatabase;
class Login;
}

namespace eedb::auth {
class Services;
}

namespace eedb {
class DefaultAuthPage final : public AuthPage {
  public:
    DefaultAuthPage(const eedb::auth::Services & baseAuth,
      std::unique_ptr< Wt::Auth::AbstractUserDatabase > userDatabase,
      Wt::Auth::Login & session);
    DefaultAuthPage(const DefaultAuthPage &) = delete;
    DefaultAuthPage(DefaultAuthPage &&);

    // clang-format off
    DefaultAuthPage & operator=(const DefaultAuthPage &) = delete;
    DefaultAuthPage & operator=(DefaultAuthPage &&);
    // clang-format on

    ~DefaultAuthPage();
    void attachTo(Wt::WContainerWidget * parent) override;
    void detach() override;
    void processEnvironment() override;

    void registerNeedVerification(std::function< void() > f) override;
    void registerOnUserWeakLogin(std::function< void() > f) override;
    void registerOnUserStrongLogin(std::function< void() > f) override;
    void registerOnUserLogout(std::function< void() > f) override;

  protected:
    void notifyUserStrongLogin() const;
    void notifyUserWeakLogin() const;
    void notifyNeedEmailVerification() const;
    void notifyUserLogout() const;

  private:
    struct DefaultAuthPagePriv;
    std::unique_ptr< DefaultAuthPagePriv > _priv;
};
}
