from dataclasses import dataclass
import json


@dataclass
class Context:
    repo_url: str = ""
    repo_branch: str = ""
    repo_commit: str = ""
    package_name: str = ""

    game_type: str = ""

    project_original_path: str = "project/original"

    temp_project_path: str = ""
    # 本地的版本号
    local_repo_branch: str = ""
    local_repo_commit: str = ""

    admob_app_id: str = ""
    game_services_project_id: str = ""
    facebook_app_id: str = ""
    facebook_client_token: str = ""

    version_display_name: str = "1"
    version_code: int = 1

    config: any = None

    sdk_version: str = ""
    sdk_prolink_version: str = ""

    out_project: str = ""
    out_debug_apk: str = ""
    out_release_apk: str = ""
    out_release_aab: str = ""

    proguard_dict: dict = None

    @classmethod
    def from_json(cls, json_str: str):
        data = json.loads(json_str)
        return cls(**data)

    def get_config(self, key: str, default_value: str = '') -> str:
        if self.config is None:
            return default_value
        return self.config.get(key, default_value).replace(" ", " ")

    def get_app_name(self):
        return self.get_config("app_name")
