from dataclasses import dataclass
from typing import LiteralString


@dataclass
class EmulatorInfo:
    index: int
    name: str
    top_handle: int
    bind_handle: int
    is_enter_android: int | None
    pid: int
    vbox_pid: int
    width: int | None
    height: int | None
    dpi: int | None


@dataclass
class PcConfig:
    pc_name: str
    officer: str | None
    use_wuyouip: int | None
    only_new: int | None
    only_retained: int | None
    check_md5_on_start: int | None
    start_dkw_on_start: int | None
    timed_start: int | None
    check_script_update: int | None
    check_image_update: int | None
    window_nums: int | None

@dataclass
class GameConfig:
    game_name: str
    cpu: str
    task_id: str  # "任务id"
    memory: str  # "内存"
    resolution: str  # "分辨率"
    is_execute: bool  # "是否执行"
    emulator_type: str  # "模拟器类型"
    channel_id: str  # "渠道id"
    game_id: str  # "游戏id"
    game_type: str  # "游戏类型"
    scale: str  # "缩放"
    script: str  # "脚本"
    timeout: int  # "超时时间"
    image: str  # "镜像"

    @staticmethod
    def dict_to_GameConfig(game: dict):
        info = GameConfig(
            cpu=game['cpu'],
            game_name=game['name'],
            task_id=game['任务id'],
            memory=game['内存'],
            resolution=str(game['分辨率']).replace('x', ',').replace('(', ',').replace(')', '').replace('dpi', ''),
            emulator_type=game['模拟器类型'],
            channel_id=game['渠道id'],
            game_id=game['游戏id'],
            game_type=game['游戏类型'],
            scale=game['缩放'],
            script=game['脚本'],
            timeout=int(game['超时时间']),
            image=game['镜像'],
            is_execute=game['是否执行'])
        return info


@dataclass
class WindowInfo:
    window_id: int
    game_list: list[GameConfig]


@dataclass
class AccountInfo:
    account: str
    password: str
    city: str
    retained: int
    retained_str: str
    manufacturer: str
    model: str
    pnumber: str
    imei: str
    imsi: str
    simserial: str
    androidid: str
    mac: str
    mac_colon: str
    iccid: str
    resolution: str
    cpuNum: str
    memorySize: str
    simulator_name: str
    wechat_order_id: str
    game_type: str
    number_operatorTypes:str


@dataclass
class UpdateInfo:
    game_id: str
    md5: str
    download_url: str
    file_type: str
    save_path: LiteralString | str | bytes


@dataclass
class UploadLog:
    simulator_ip: str  # 模拟器ip
    simulator_mac: str  # 模拟器mac
    pc_code: str  # 电脑编号
    pc_ip: str  # 电脑IP
    pc_mac: str  # 电脑mac
    device_id: str  # 手机_aid
    account: str  # 游戏账号
    account_type: int  # 游戏_账号类型
    pwd: str  # 游戏账号密码
    game_id: int  # 游戏编号
    coding: int  # 错误码
    log_uuid: str
    operator: str  # 负责人
    remarks: str  # 备注
    task_type: int  # 任务类型新增0活跃1
    script_type: int  # 脚本类型
    simulator_code: str  # 模拟器编号
    device_manufacturer: str  # 手机_厂商
    device_model: str  # 手机_型号
    device_imei: str  # 手机_imei
    device_sdk: str  # 手机_sdk
    device_mac: str  # 手机_mac
    device_number: str  # 手机_号码
    script_device_id: str  # 脚本中上传
    err: str  # 0或不传表示没有异常，其他表示异常，脚本端自定义
    simulator_ip_city: str  # 手机_IP_城市

    # 定义一个方法，将对象转换为字典
    def to_dict(self):
        return {
            'simulator_ip': self.simulator_ip,
            'simulator_mac': self.simulator_mac,
            'pc_code': self.pc_code,
            'pc_ip': self.pc_ip,
            'pc_mac': self.pc_mac,
            'device_id': self.device_id,
            'account': self.account,
            'account_type': self.account_type,
            'pwd': self.pwd,
            'game_id': self.game_id,
            'coding': self.coding,
            'log_uuid': self.log_uuid,
            'operator': self.operator,
            'remarks': self.remarks,
            'task_type': self.task_type,
            'script_type': self.script_type,
            'simulator_code': self.simulator_code,
            'device_manufacturer': self.device_manufacturer,
            'device_model': self.device_model,
            'device_imei': self.device_imei,
            'device_sdk': self.device_sdk,
            'device_mac': self.device_mac,
            'device_number': self.device_number,
            'script_device_id': self.script_device_id,
            'err': self.err,
            'simulator_ip_city': self.simulator_ip_city
        }
