#pragma once
#include <string>
#include <vector>
#include <functional>

class GetbinClient {
public:
    // Constructor accepting server list for multi-server support
    GetbinClient(const std::vector<std::string>& servers);
    
    // Backward compatibility constructor (uses default server)
    GetbinClient();
    
    // Progress callback: (downloaded_bytes, total_bytes) -> should_continue
    using ProgressCallback = std::function<bool(size_t, size_t)>;
    
    // Multi-server download with fallback logic
    bool download(const std::string& toolName, const std::string& arch, const std::string& outPath, 
                  ProgressCallback progressCallback = nullptr);
    
    // Server-specific download
    bool downloadFromServer(const std::string& serverUrl, const std::string& toolName, 
                           const std::string& arch, const std::string& outPath, 
                           ProgressCallback progressCallback = nullptr);
    
    // Server-specific upload
    bool upload(const std::string& serverUrl, const std::string& archivePath, 
                std::string& outUrl, std::string& outHash, const std::string& token,
                ProgressCallback progressCallback = nullptr);
    
    // Backward compatibility upload (uses first server)
    bool upload(const std::string& archivePath, std::string& outUrl, std::string& outHash, const std::string& token,
                ProgressCallback progressCallback = nullptr);
    
    // Server-specific hash retrieval
    bool getHash(const std::string& serverUrl, const std::string& toolName, 
                 const std::string& arch, std::string& outHash);
    
    // Multi-server hash retrieval with fallback
    bool getHash(const std::string& toolName, const std::string& arch, std::string& outHash);
    
    // Find which server has a specific package
    bool findPackageServer(const std::string& toolName, const std::string& arch, 
                          std::string& foundServer) const;
    
    // Legacy methods (use first server for backward compatibility)
    bool deleteObject(const std::string& hash, const std::string& token);
    bool listPackages(std::vector<std::string>& outPackages);
    bool listAllEntries(std::vector<std::pair<std::string, std::vector<std::string>>>& outEntries);
    
private:
    static const std::string DEFAULT_SERVER_HOST;
    std::vector<std::string> servers_;
    
    std::string getUserAgent() const;
    std::string buildUrl(const std::string& serverUrl, const std::string& endpoint) const;
};
