"""Check Usage Logs"""
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))

from app.database import SessionLocal
from app.models.usage import UsageLog
from sqlalchemy import desc

def check_logs():
    db = SessionLocal()
    try:
        count = db.query(UsageLog).count()
        print(f"Total Usage Logs: {count}")
        
        if count > 0:
            latest = db.query(UsageLog).order_by(desc(UsageLog.created_at)).first()
            print(f"Latest Log: {latest.module} | {latest.action} | {latest.created_at}")
            print(f"Metadata: {latest.request_metadata}")
    finally:
        db.close()

if __name__ == "__main__":
    check_logs()
