# === osaf_core.py ===

import subprocess

import psutil

from libs.osaf.common.files import OSAFiles
from libs.osaf.common.osaf_common import OSAUtils, OSATime
from libs.osaf.common.proc import OSAProcesses
from libs.osaf.common.resources import OSResources
from libs.osaf.common.web import OSAWeb
from libs.osaf.integrations.linux.linux_pd import LinuxPD
from libs.osaf.integrations.nt.NT_Detect import NT_Detect
from libs.spider_logger import logger

osa_sample_conf = {
    "platform": {
        "arch_aliases": {
            "x86": ["i386", "i486", "i686", "IA-32", "x86-32"],
            "x86-64": ["amd64", "Intel64", "EM64T", "x86_64", "x64"],
            "IA-64": ["Itanium"],
            "AArch32": ["ARM", "ARM32", "armv7"],
            "AArch64": ["ARM64", "armv8", "armv9"],
            "E2K": []
        }
    },
    "osa_assets_path" : "libs/osaf/assets/"
}


class OSAF_Platform:
    def __dir__(self, osa):
        self.os_conf = osa.conf.get("os_conf")




class OSAF_Core:

    def __init__(self, logger: logger.SpiderLog, master_workdir, conf=None):
        if conf is None:
            conf = osa_sample_conf
            conf['osa_assets_path'] = master_workdir + "/" + conf['osa_assets_path']
        self.conf = conf

        self.ext = {}
        self.users_data = []
        self.log = logger
        self.master_workdir = master_workdir

        # Общие компоненты (кроссплатформенные)
        self.time = OSATime(self)
        self.processes = OSAProcesses(self)
        self.files = OSAFiles(self)
        self.web = OSAWeb(self)
        self.utils = OSAUtils(conf)

        # OS-специфичные компоненты
        if self.utils.is_windows():
            self.platform = NT_Detect(self, f"{conf['osa_assets_path']}/data/nt/")

        if self.utils.is_linux():
            self.platform = LinuxPD(self, f"{conf['osa_assets_path']}/data/linux/")
            # self.packages = LX_Packages(self)

        self.packages = None
        self.resources = OSResources(self)
