# Temporary models file - will be expanded in Phase 3
from db import execute_query


def get_user_by_username(username):
    """Get user from database by username"""
    result = execute_query(
        """
        SELECT id, username, password_hash, email, totp_secret, totp_enabled, 
               backup_codes, last_password_change, failed_2fa_attempts
        FROM users WHERE username = %s
        """,
        (username,),
        fetch_one=True
    )
    
    if result:
        return {
            'id': result[0],
            'username': result[1],
            'password_hash': result[2],
            'email': result[3],
            'totp_secret': result[4],
            'totp_enabled': result[5],
            'backup_codes': result[6],
            'last_password_change': result[7],
            'failed_2fa_attempts': result[8]
        }
    return None