import sys
import os
sys.path.insert(1,f"{sys.path[0]}/py_module")
os.chdir(sys.path[0])

from .base import Base
from .whiptail_installer import Whiptail_installer
from .installer import Installer
from .runner import Runner
from .updates import Updates
from .maintenance import Maintenance
from .team_install import Team_install
from .media_install import Media_install
from .integrations import Integrations
from .ins_eula import Ins_Eula
__author__ = "Talipov Ilja, Ayupov Rinat"
__contact__ = "+7 (982) 255-78-38, +7 (924) 271-61-00"
__copyright__ = "2025 R7.inc"
__license__ = "Commercial"
__version__ = "2025.3.12.15877"
__email__ = "support@r7-office.ru"
__maintainer__ = "Shagov Ivan"
__date__ = "2025/04/05"
__status__ = "Production"
__all__ = ["Init"]


class Init(Base):

    def preload(self):
        self.semaphore = ["Выберите необходимое действие:",[]];
        self.semaphore[1].append(
                {
                    "lang": "Лицензионное соглашение Р7-Офис",
                    "exec": Ins_Eula,
                    "logger_name": "Installer",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Корпоративный сервер 2024, Сервер документов и Почтовый сервер",
                    "exec": Installer,
                    "logger_name": "Installer",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Р7 Команды - сервер управления",
                    "exec": Team_install,
                    "logger_name": "Team_install",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Р7 Команды - медиа сервер",
                    "exec": Media_install,
                    "logger_name": "Media_install",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Запуск/Остановка компонентов системы",
                    "exec": Runner,
                    "logger_name": "Runner",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Интеграции",
                    "exec": Integrations,
                    "logger_name": "Maintenance",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Обслуживание",
                    "exec": Maintenance,
                    "logger_name": "Maintenance",
                    "logger_level": self.logger_level
                }
        );
        self.semaphore[1].append(
                {
                    "lang": "Обновление",
                    "exec": Updates,
                    "logger_name": "Updates",
                    "logger_level": self.logger_level
                }
        );
        self.logger.info("Проверяю наличие whiptail в системе и произвожу установку в случае отсутствия")
        with Whiptail_installer() as run:
            pass

    def callback(self, response):
        self.semaphore[1][0]={
                    "lang": "Обновление продукта Р7-Офис",
                    "exec": Installer,
                    "logger_name": "Installer",
                    "logger_level": self.logger_level
        }
