#ifndef CONNECTIONWIZARD_H
#define CONNECTIONWIZARD_H

#include <QWizard>
#include <QLineEdit>
#include <QComboBox>
#include <QCheckBox>
#include <QIntValidator>
#include <QLabel>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QPushButton>
#include <QGroupBox>
#include <QRadioButton>
#include "core/models/account.h"
#include "services/accountservice.h"

class ConnectionWizard : public QWizard {
    Q_OBJECT

public:
    explicit ConnectionWizard(QWidget *parent = nullptr, AccountService *accountService = nullptr);
    ~ConnectionWizard() override = default;

    // Retrieve the filled connection settings
    Account::ConnectionSettings connectionSettings() const;

signals:
    void settingsReady(const Account::ConnectionSettings &settings);

private slots:
    void accept() override;
    void onTestClicked();

private:
    void setupPageIntro();
    void setupPageIncoming();
    void setupPageOutgoing();
    void setupPageAuth();
    void setupPageTest();

    // Page pointers (optional)
    QWizardPage *m_introPage;
    QWizardPage *m_incomingPage;
    QWizardPage *m_outgoingPage;
    QWizardPage *m_authPage;
    QWizardPage *m_testPage;

    // Incoming fields
    QComboBox *m_incomingTypeCombo; // IMAP, POP3
    QLineEdit *m_incomingHostEdit;
    QLineEdit *m_incomingPortEdit;
    QCheckBox *m_incomingSslCheck;

    // Outgoing fields
    QLineEdit *m_outgoingHostEdit;
    QLineEdit *m_outgoingPortEdit;
    QCheckBox *m_outgoingSslCheck;

    // Auth fields
    QLineEdit *m_usernameEdit;
    QLineEdit *m_passwordEdit;
    QComboBox *m_authMethodCombo; // Plain, Login, OAuth2 (if supported)

    // Test page
    QLabel *m_testStatusLabel;
    QLabel *m_testDetailLabel;
    QPushButton *m_testButton;

    AccountService *m_accountService;
};

#endif // CONNECTIONWIZARD_H