from functools import wraps
import sys, os
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
import core.logger as logger
log = logger.get_logger()
from database.base import BaseConfig, AutoInstanceDecorator
from database.dirs import CheckDirAliasDecorator
from database.common import *

@AutoInstanceDecorator
class GIT_REMOTE_REPO(BaseConfig):
    _config = "origin"

@AutoInstanceDecorator
class TAG_IGNORE_PROJECT(BaseConfig):
    _config = "build"

@AutoInstanceDecorator
class TAR_EXFILES(BaseConfig):
    _config = "--exclude=.git --exclude=.svn --exclude=.gitignore --exclude=.vimproj"

@AutoInstanceDecorator
class RELEASE_SNAPSHOT(BaseConfig):
    _config = ".repo/manifests/release_snapshot/"

@AutoInstanceDecorator
class REPO_URL(BaseConfig):
    _config = "http://hcgit04:9080/manifest/alkaid"


@AutoInstanceDecorator
class ProductIngoreList(BaseConfig):
    _config = [
            "include",
            "sigma_common_libs",
        ]
    def check(self) -> bool:
        # 检查当前 配置是否合法
        return True

@AutoInstanceDecorator
class ChipIngoreList(BaseConfig):
    _config = [
            "ifado",
            "iford",
            "maruko",
            "opera",
            "pcupid",
            "souffle",
            "mercury6p",
            "infinity6c",
            "infinity6e",
            "infinity6f",
            "infinity7",
            "pioneer5",
            "ibopper",
            #---chip support OpenRtosCm4SourceEx after ifackel
            "ifackel",
        ]

@AutoInstanceDecorator
class ChipCheckConfigConsistencyList(BaseConfig):
    _config = [
            "iford",
            "ifado",
            "ibopper",
            "pcupid",
            "ifackel",
        ]

@AutoInstanceDecorator
class ReleaseDirDefaultList(BaseConfig):
    _config = [
            "boot",
            "kernel",
            "optee",
            "pm_rtos",
            "project",
            "riscv",
            "rtos",
            "sdk",
        ]
    def check(self) -> bool:
        for item in self._list:
            if not check_file_exists(item):
                log.warning(f"path {item} not exists")
        return True

@AutoInstanceDecorator
class ExReleaseList(BaseConfig):
    _config = [
            "sdk/driver",
        ]
    def check(self) -> bool:
        for item in self._list:
            if not check_file_exists(item):
                raise ValueError(f"path {item} not exiest")
        return True

@AutoInstanceDecorator
class AppDemoDefaultList(BaseConfig):
    """DEMO_LIST default files
    """
    _config = [
            "sdk/makefile",
            "sdk/sdk.mk",
            "sdk/verify/makefile",
        ]
    def check(self) -> bool:
        for item in self._list:
            if not check_file_exists(item):
                raise ValueError(f"path {item} not exists")
        return True

@AutoInstanceDecorator
@CheckDirAliasDecorator
class RtosDefaultList(BaseConfig):
    """RTOS default drivers
    """
    _config = [
            "bench",
            "bootloader",
            "dualos_camera",
            "cust_isp",
            "cust_usb_gadget",
            "earlyinit_setting",
            "earlyinit_main",
            "earlyinit_vsrc",
            "sysdesc",
            "sensordriver",
        ]

@AutoInstanceDecorator
@CheckDirAliasDecorator
class RtosWhiteList(BaseConfig):
    """RTOS white drivers
    """
    _config = [
            "application_selector",
            "aov_preload",
            "cm4_preload",
            "coremark",
            "common",
            "audio_app",
            "disp_app",
            "dualos_camera",
            "font",
            "iqserver",
            "lvgl",
            "sample_code",
            "preload_rtos",
            "preload_sample",
            "usb_gadget_app",
            "usb_gadget_app_uvc",
            "sensordriver", 
            "aesdma",
            "bdma",
            "camclk",
            "cpufreq",
            "drvutil",
            "emac",
            "fcie",
            "flash",
            "fsp_qspi",
            "gpio",
            "i2c",
            "input",
            "int",
            "ir",
            "kernel",
            "loadns",
            "mbx",
            "miu",
            "mmupte",
            "mspi",
            "msys",
            "padmux",
            "pwm",
            "riu",
            "rtc",
            "rtcpwc",
            "saradc",
            "sdmmc",
            "str",
            "timer",
            "tsensor",
            "uart",
            "voltage",
            "watchdog",
            "algo",
            "decompress",
            "freertos_plus_fat",
            "lwfs",
            "proxyfs",
            "tcpip",
            "arm",
            "riscv",
            "libc",
            "newlib_stub",
            "cam_dev_wrapper",
            "cam_drv_poll",
            "cam_fs_wrapper",
            "cam_os_wrapper",
            "cam_proc_wrapper",
            "env_util",
            "initcall",
            "loadable_module",
            "memmang",
            "memmap",
            "mempool",
            "MsWrapper",
            "newlib_stub",
            "freertos_main",
            "freertos_posix",
            "sys_I_SW",
        ]

@AutoInstanceDecorator
@CheckDirAliasDecorator
class PmRtosDefaultList(BaseConfig):
    """PM_RTOS default drivers
    """
    _config = [
            "pm_slnn_raw_hpd",
            "pm_cm4_pipeline",
            "pm_sysdesc",
    ]

@AutoInstanceDecorator
@CheckDirAliasDecorator
class PmRtosWhiteList(BaseConfig):
    """PM_RTOS white drivers
    """
    _config = [
            "pm_aesdma",
            "pm_bdma",
            "pm_camclk",
            "pm_cpufreq",
            "pm_drvutil",
            "pm_loadns",
            "pm_emac",
            "pm_flash",
            "pm_fsp_qspi",
            "pm_gpio",
            "pm_i2c",
            "pm_int",
            "pm_ir",
            "pm_kernel",
            "pm_miu",
            "pm_mmupte",
            "pm_mspi",
            "pm_msys",
            "pm_padmux",
            "pm_pcie",
            "pm_pl011",
            "pm_mhal_pm_clk",
            "pm_pm_idle",
            "pm_mhal_pm_mbx",
            "pm_mhal_imi_heap",
            "pm_mhal_pm_pir",
            "pm_rtcpwc",
            "pm_mhal_pm_sys",
            "pm_mhal_pm_wdt",
            "pm_pspi",
            "pm_pwm",
            "pm_pm_power",
            "pm_rtc",
            "pm_rtcpwc",
            "pm_saradc",
            "pm_sdmmc",
            "pm_timer",
            "pm_tsensor",
            "pm_uart",
            "pm_voltage",
            "pm_watchdog",
            "pm_decompress",
            "pm_freertos_plus_fat",
            "pm_lwfs",
            "pm_proxyfs",
            "pm_tcpip",
            "pm_arm",
            "pm_riscv",
            "pm_cam_dev_wrapper",
            "pm_cam_drv_poll",
            "pm_cam_fs_wrapper",
            "pm_cam_os_wrapper",
            "pm_cam_proc_wrapper",
            "pm_env_util",
            "pm_initcall",
            "pm_libc",
            "pm_memmang",
            "pm_memmap",
            "pm_mempool",
            "pm_MsWrapper",
            "pm_freertos",
            "pm_freertos_posix",
            "pm_sys_I_SW",
    ]


@AutoInstanceDecorator
class DemoListDefault(BaseConfig):
    """DEMO_LIST_DEFAULT
    """
    _config = [
    ]
