import sys
import os

CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
if CURRENT_DIR not in sys.path:
    sys.path.insert(0, CURRENT_DIR)

from app import create_app, db
from models import Admin
import pyotp

app = create_app({"DISABLE_SCHEDULER": True})
with app.app_context():
    admin = Admin.query.first()
    if admin:
        print(f"Admin: {admin.username}, TOTP Enabled: {admin.totp_enabled}")
        print(f"TOTP Secret: {admin.totp_secret}")
        if admin.totp_secret:
            try:
                totp = pyotp.TOTP(admin.totp_secret)
                print(f"Current TOTP Code: {totp.now()}")
            except Exception as e:
                print(f"PyOTP Error: {e}")
        else:
            print("No TOTP secret set.")
    else:
        print("No admin found.")
