#include <iostream>

#include "authguard.hpp"

int main() {
    try {
        // Copy these from Dashboard -> your app -> Settings.
        authguard::AuthGuard app("YOUR_APP_ID", "1.0", "YOUR_PUBLIC_KEY", "https://authguard.dk/api/client");
        app.init();

        std::cout << "1) License key  2) Login  3) Register\n> ";
        std::string choice, user, pass, key;
        std::getline(std::cin, choice);
        if (choice == "1") {
            std::cout << "License key: "; std::getline(std::cin, key);
            app.license(key);
        } else if (choice == "2") {
            std::cout << "Username: "; std::getline(std::cin, user);
            std::cout << "Password: "; std::getline(std::cin, pass);
            app.login(user, pass);
        } else {
            std::cout << "Username: "; std::getline(std::cin, user);
            std::cout << "Password: "; std::getline(std::cin, pass);
            std::cout << "License key: "; std::getline(std::cin, key);
            app.register_user(user, pass, key);
        }
        std::cout << "Access granted. Expires: " << (app.info["expires_at"].is_null() ? "never" : app.info["expires_at"].get<std::string>()) << "\n";
    } catch (const authguard::Error& e) {
        if (e.update_required()) std::cout << "Update required. Download: " << e.download_url() << "\n";
        else std::cout << "Error: " << e.what() << "\n";
        return 1;
    }
    return 0;
}
