from app.models import init_db, SessionLocal
from app.models.user import User
from app.utils.security import verify_password, get_password_hash

def test_login():
    db = SessionLocal()
    email = "admin@example.com"
    password = "admin"
    
    user = db.query(User).filter(User.email == email).first()
    if not user:
        print(f"User {email} not found!")
        return

    print(f"User found: {user.email}")
    print(f"Stored Hash: {user.password_hash}")
    
    # Test verification
    is_valid = verify_password(password, user.password_hash)
    print(f"Password '{password}' valid? {is_valid}")
    
    if not is_valid:
        print("Attempting to reset password...")
        user.password_hash = get_password_hash(password)
        db.commit()
        print("Password reset. Testing again...")
        is_valid = verify_password(password, user.password_hash)
        print(f"Password '{password}' valid? {is_valid}")

    db.close()

if __name__ == "__main__":
    test_login()
