import hashlib
import random

from app.config.config import AppCtx


def md5(s: str) -> str:
    m = hashlib.md5()
    m.update(s.encode('utf-8'))
    return m.hexdigest()


def get_proxies():
    # username = "t14131310374591"
    # password = "qg6xwmrq"
    # tunnel = "d432.kdltps.com:15818"
    # proxies = {
    #     "http": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel},
    #     "https": "http://%(user)s:%(pwd)s@%(proxy)s/" % {"user": username, "pwd": password, "proxy": tunnel}
    # }
    # proxies = {
    #     "http": "http://127.0.0.1:8080",
    #     "https": "http://127.0.0.1:8080"
    # }

    proxy = AppCtx.g_app_config.chrome.proxy
    proxies = {
        "http": proxy,
        "https": proxy
    }

    return proxies


def get_all_cookies():
    cookies_holder = []

    def inner():
        if not cookies_holder:
            for line in open('./data/live_cookies.txt', 'r'):
                line = line.strip()
                if line:
                    cookies_holder.append(line)

        return cookies_holder

    return inner()


def report_keywords():
    return [
        "成人", "av", "亚洲", "日韩", "欧美", "国产", "无码", "黄色", "丝袜", "少妇", "人妻"
    ]


def get_reporter_name():
    surnames = [
        "李", "王", "张", "刘", "陈", "杨", "赵", "黄", "周", "吴", "徐", "孙", "胡", "朱", "高", "林",
        "何", "郭", "马", "罗", "梁", "宋", "郑", "谢", "韩", "唐", "冯", "于", "董", "萧", "程", "曹",
        "袁", "邓", "许", "傅", "沈", "曾", "彭", "吕", "苏", "卢", "蒋", "蔡", "贾", "丁", "魏", "薛"
    ]

    # 常用名字字
    name_characters = [
        "伟", "芳", "娜", "敏", "静", "丽", "强", "磊", "军", "洋", "勇", "艳", "杰", "娟", "涛", "明",
        "超", "秀", "霞", "平", "刚", "桂", "梅", "琳", "华", "中", "建", "丹", "飞", "玲", "彬", "祥",
        "辉", "良", "俊", "志", "红", "玉", "斌", "宇", "浩", "燕", "晨", "泽", "昊", "欣", "帆", "瑞"
    ]
    xing = random.choice(surnames)
    ming = random.choice(name_characters)
    ming2 = random.choice(name_characters)
    if random.choice([True, False]):
        return f"{xing}{ming}"
    else:
        return f"{xing}{ming}{ming2}"


def generate_random_phone_number():
    """
    随机生成一个国内11位手机号
    """
    # 常见的手机号段前3位（移动、联通、电信等）
    prefixes = [
        "134", "135", "136", "137", "138", "139",  # 移动号段
        "150", "151", "152", "157", "158", "159",  # 移动号段
        "130", "131", "132", "155", "156",  # 联通号段
        "133", "153", "180", "181", "189",  # 电信号段
        "177", "173", "175",  # 其他号段
        "199", "198", "166",  # 新号段
        "186", "187", "188", "139"  # 常见号段
    ]

    # 随机选择一个前缀
    prefix = random.choice(prefixes)

    # 随机生成剩余的8位数字
    suffix = ''.join(random.choices("0123456789", k=8))

    # 返回完整的手机号
    return prefix + suffix
