#include <QApplication>
#include <QMainWindow>
#include <QDebug>

#include "core/translator.h"
#include "db/databasemanager.h"
#include "core/eventbus.h"
#include "utils/notificationmanager.h"
#include "syncscheduler.h"
#include "ui/mainmainwindow.h"
#include "services/accountservice.h"
#include "services/mailservice.h"
#include "db/dao/folderdao.h"

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    app.setApplicationName("Wino Mail");
    app.setApplicationVersion("1.0.0");
    app.setOrganizationName("Wino");

    qDebug() << "[main] Starting Wino Mail";

    // Initialize subsystems
    qDebug() << "[main] Initializing DatabaseManager";
    if (!DatabaseManager::instance().initialize()) {
        qCritical() << "[main] Database initialization failed";
        return 1;
    }
    qDebug() << "[main] DatabaseManager initialized";

    EventBus &bus = EventBus::instance();
    qDebug() << "[main] EventBus created";
    NotificationManager notificationManager(&bus);
    qDebug() << "[main] NotificationManager created";

    // Start background sync
    qDebug() << "[main] Creating SyncScheduler";
    SyncScheduler syncScheduler(&bus);
    qDebug() << "[main] Starting SyncScheduler";
    // syncScheduler.start();  // Temporarily disabled for debugging
    qDebug() << "[main] SyncScheduler created (not started)";

    // Create main window
    qDebug() << "[main] Creating MainMainWindow";
    MainMainWindow window;
    qDebug() << "[main] MainMainWindow created, showing window";
    window.show();
    qDebug() << "[main] Window shown, entering event loop";

    qDebug() << "Wino Mail started successfully";

    return app.exec();
}
