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(query_params):
    """Build a LookupCredentials from HTTP query params; returns None if no usable credentials are present."""
    creds = LookupCredentials(
        qrz_username=query_params.get("qrz_username", ""),
        qrz_password=query_params.get("qrz_password", ""),
        qrz_session_key=query_params.get("qrz_session_key", ""),
        hamqth_username=query_params.get("hamqth_username", ""),
        hamqth_password=query_params.get("hamqth_password", ""),
        hamqth_session_id=query_params.get("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
