// DragonX Wallet - ImGui Edition
// Copyright 2024-2026 The Hush Developers
// Released under the GPLv3

#pragma once

#include "wallet_capabilities.h"

#include <cstdint>
#include <optional>
#include <string>
#include <vector>

namespace dragonx {
namespace wallet {

enum class WalletBackendState {
    Unavailable,
    Disconnected,
    Connecting,
    Syncing,
    Ready,
    Error
};

struct WalletBackendStatus {
    WalletBackendState state = WalletBackendState::Unavailable;
    std::string message;
    std::optional<int> walletHeight;
    std::optional<int> chainHeight;
    double syncProgress = 0.0;
};

struct WalletBackendResult {
    bool ok = false;
    std::string error;
};

struct WalletOpenRequest {
    std::string walletPath;
    std::string serverUrl;
    bool restoreFromSeed = false;
};

struct WalletSendRequest {
    std::string fromAddress;
    std::string toAddress;
    double amount = 0.0;
    double fee = 0.0;
    std::string memo;
};

struct WalletSendResult {
    bool accepted = false;
    std::string txid;
    std::string error;
};

class WalletBackend {
public:
    virtual ~WalletBackend() = default;

    virtual WalletBackendKind kind() const = 0;
    virtual WalletCapabilities capabilities() const = 0;
    virtual WalletBackendStatus status() const = 0;
};

class FullNodeWalletBackend : public WalletBackend {
public:
    ~FullNodeWalletBackend() override = default;
};

class LiteWalletBackend : public WalletBackend {
public:
    ~LiteWalletBackend() override = default;

    virtual WalletBackendResult setServer(const std::string& serverUrl) = 0;
    virtual WalletBackendResult openWallet(const WalletOpenRequest& request) = 0;
    virtual WalletBackendResult startSync() = 0;
    virtual WalletBackendResult cancelSync() = 0;
    virtual WalletSendResult sendTransaction(const WalletSendRequest& request) = 0;
};

class WalletBackendRouter {
public:
    virtual ~WalletBackendRouter() = default;

    virtual WalletBackend& activeBackend() = 0;
    virtual const WalletBackend& activeBackend() const = 0;
};

} // namespace wallet
} // namespace dragonx