"""
UA / TLS 指纹精确配对池

- 每条 profile 内部自洽：UA 版本 == impersonate 版本，sec-ch-ua 品牌版本与之一致，
  操作系统仅 Windows / macOS。
- impersonate 取值均为 curl_cffi 0.13 原生支持的较新桌面 Chrome 目标，
  避免出现「UA 说 136、TLS 指纹是 131」这种错位。
- 真实 Chrome on Mac 的系统号冻结在 10_15_7。
"""
import random

UA_TLS_PROFILES = [
    # ---- Windows ----
    {"impersonate": "chrome136", "version": "136", "platform": "Windows",
     "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},
    {"impersonate": "chrome131", "version": "131", "platform": "Windows",
     "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"},
    {"impersonate": "chrome124", "version": "124", "platform": "Windows",
     "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"},
    {"impersonate": "chrome120", "version": "120", "platform": "Windows",
     "ua": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"},
    # ---- macOS ----
    {"impersonate": "chrome136", "version": "136", "platform": "macOS",
     "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"},
    {"impersonate": "chrome131", "version": "131", "platform": "macOS",
     "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"},
    {"impersonate": "chrome123", "version": "123", "platform": "macOS",
     "ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"},
]


def build_browser_headers():
    """随机选一条 profile，返回 (headers, impersonate)。

    headers 中的 UA、sec-ch-ua、sec-ch-ua-platform 三者与所选 impersonate 自洽，
    每次请求调用一次即可。
    """
    profile = random.choice(UA_TLS_PROFILES)
    v = profile["version"]
    headers = {
        "accept": "text/html,application/xhtml+xml,*/*",
        "Accept-Language": "en-US,en;q=0.9",
        "Accept-Encoding": "gzip, deflate",
        "user-agent": profile["ua"],
        "sec-ch-ua": f'"Chromium";v="{v}", "Google Chrome";v="{v}", "Not.A/Brand";v="99"',
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": f'"{profile["platform"]}"',
    }
    return headers, profile["impersonate"]
