"""跨俱乐部资产迁移 — 资产字段白名单字典（只迁登记过的字段）。"""
from __future__ import annotations

from typing import Dict, List, Tuple

# key = "role.field" ；huiyuan 为特殊包
ASSET_CATALOG: Dict[str, dict] = {
    'dashou.yue': {'role': 'dashou', 'field': 'yue', 'label': '打手可提现', 'kind': 'money'},
    'dashou.yajin': {'role': 'dashou', 'field': 'yajin', 'label': '打手押金', 'kind': 'money'},
    'dashou.jifen': {'role': 'dashou', 'field': 'jifen', 'label': '打手积分', 'kind': 'int'},
    'dashou.dongjie_yue': {'role': 'dashou', 'field': 'dongjie_yue', 'label': '打手冻结资金', 'kind': 'money'},
    'dashou.huiyuan': {'role': 'dashou', 'field': 'huiyuan', 'label': '打手会员资格', 'kind': 'huiyuan'},
    'shangjia.yue': {'role': 'shangjia', 'field': 'yue', 'label': '商家余额', 'kind': 'money'},
    'guanshi.yue': {'role': 'guanshi', 'field': 'yue', 'label': '管事可提现', 'kind': 'money'},
    'guanshi.dongjie_yue': {'role': 'guanshi', 'field': 'dongjie_yue', 'label': '管事冻结资金', 'kind': 'money'},
    'zuzhang.ketixian_jine': {'role': 'zuzhang', 'field': 'ketixian_jine', 'label': '组长可提现', 'kind': 'money'},
    'zuzhang.dongjie_yue': {'role': 'zuzhang', 'field': 'dongjie_yue', 'label': '组长冻结资金', 'kind': 'money'},
    'shenheguan.yue': {'role': 'shenheguan', 'field': 'yue', 'label': '考核官可提现', 'kind': 'money'},
    'shenheguan.dongjie_yue': {'role': 'shenheguan', 'field': 'dongjie_yue', 'label': '考核官冻结资金', 'kind': 'money'},
}

ROLE_PROFILE_ATTR = {
    'dashou': 'DashouProfile',
    'shangjia': 'ShopProfile',
    'guanshi': 'GuanshiProfile',
    'zuzhang': 'ZuzhangProfile',
    'shenheguan': 'ShenheguanProfile',
}


def normalize_whitelist(raw) -> List[str]:
    if not raw:
        return []
    out = []
    seen = set()
    for x in raw:
        k = str(x or '').strip()
        if k in ASSET_CATALOG and k not in seen:
            seen.add(k)
            out.append(k)
    return out


def catalog_for_admin() -> List[dict]:
    return [
        {'key': k, 'label': v['label'], 'role': v['role'], 'field': v['field'], 'kind': v['kind']}
        for k, v in ASSET_CATALOG.items()
    ]


def roles_from_whitelist(keys: List[str]) -> List[str]:
    roles = []
    seen = set()
    for k in keys:
        meta = ASSET_CATALOG.get(k)
        if not meta:
            continue
        r = meta['role']
        if r not in seen:
            seen.add(r)
            roles.append(r)
    return roles
