import sys

from authguard import AuthGuard, AuthGuardError

# Copy these from Dashboard -> your app -> Settings.
app = AuthGuard(
    app_id="YOUR_APP_ID",
    version="1.0",
    public_key="YOUR_PUBLIC_KEY",
    url="https://authguard.dk/api/client",
)

try:
    app.init()
except AuthGuardError as e:
    if e.response.get("update_required"):
        print("Update required. Download:", e.response.get("download_url"))
    else:
        print("Error:", e)
    sys.exit(1)

choice = input("1) License key  2) Login  3) Register\n> ").strip()
try:
    if choice == "1":
        app.license(input("License key: "))
    elif choice == "2":
        app.login(input("Username: "), input("Password: "))
    else:
        app.register(input("Username: "), input("Password: "), input("License key: "))
except AuthGuardError as e:
    print("Error:", e)
    sys.exit(1)

print("Access granted. Expires:", app.info.get("expires_at") or "never")
# Example: fetch a server-side variable (create it under Variables in the dashboard)
# print(app.var("download_link"))
