#ifndef __APPLICATION_H__
#define __APPLICATION_H__

#include "Base/Messages.h"
#include <boost/asio/io_context.hpp>
#include <memory>

namespace Core {
class IoContext;
class MessageManager;
} // namespace Core

namespace WeChat {
namespace Corporation {
class Context;
}
} // namespace WeChat

namespace Older {

class Settings;
class ApplicationPrivate;
class HttpSession;
class Database;
class SessionStore;
class SignalServer;

class Application : public std::enable_shared_from_this<Application> {
public:
    using Pointer = std::shared_ptr<Application>;
    Application();
    ~Application();
    boost::asio::io_context &ioContext();
    void startAcceptHttpConnections(const std::string &address, uint16_t port);
    void insertUrl(std::string_view url, RequestHandler &&handler);
    int exec();
    void exit(int returnCode = 0);

protected:
    void asyncAcceptHttpConnections();

private:
    ApplicationPrivate *m_d = nullptr;
    int m_returnCode = 0;
    std::shared_ptr<Settings> m_settings;
    std::shared_ptr<Core::IoContext> m_ioContext;
    std::shared_ptr<Core::MessageManager> m_messageManager;
    std::shared_ptr<SessionStore> m_sessionStore;
    std::shared_ptr<Database> m_database;
    std::shared_ptr<WeChat::Corporation::Context> m_corporationContext;
    std::shared_ptr<SignalServer> m_signalServer;
};
} // namespace Older
#endif // __APPLICATION_H__