from dataclasses import dataclass


@dataclass
class LookupCredentials:
    """Per-request credentials for QRZ.com and HamQTH online callsign lookups."""
    qrz_username: str = ""
    qrz_password: str = ""
    qrz_session_key: str = ""  # alternative to username/password
    hamqth_username: str = ""
    hamqth_password: str = ""
    hamqth_session_id: str = ""  # alternative to username/password


def extract_credentials(headers):
    """Build a LookupCredentials from HTTP request headers; returns None if no usable credentials are present."""
    creds = LookupCredentials(
        qrz_username=headers.get("X-QRZ-Username", ""),
        qrz_password=headers.get("X-QRZ-Password", ""),
        qrz_session_key=headers.get("X-QRZ-Session-Key", ""),
        hamqth_username=headers.get("X-HamQTH-Username", ""),
        hamqth_password=headers.get("X-HamQTH-Password", ""),
        hamqth_session_id=headers.get("X-HamQTH-Session-ID", ""),
    )
    has_qrz = creds.qrz_session_key or (creds.qrz_username and creds.qrz_password)
    has_hamqth = creds.hamqth_session_id or (creds.hamqth_username and creds.hamqth_password)
    return creds if (has_qrz or has_hamqth) else None
