from typing import Dict

from application.model import UpdateType
from application.util import settings


class PosVersions(object):
    def __init__(
        self,
        last_versions,          # type: Dict[int, str]
        last_versions_dates,    # type: Dict[int, str]
        menu_version,           # type: str
        menu_name,              # type: str
    ):
        # type: (...) -> None

        catalog = last_versions[UpdateType.catalog.value] if UpdateType.catalog.value in last_versions else ""
        catalog_json_value = UpdateType.catalog_json.value
        catalog_json = last_versions[catalog_json_value] if catalog_json_value in last_versions else ""
        user = last_versions[UpdateType.user.value] if UpdateType.user.value in last_versions else ""
        loader = last_versions[UpdateType.loader.value] if UpdateType.loader.value in last_versions else ""
        binaries = last_versions[UpdateType.binaries.value] if UpdateType.binaries.value in last_versions else ""
        core = binaries.split("|")[0].split(":")[1] if binaries != "" else ""
        src = binaries.split("|")[1].split(":")[1] if binaries != "" else ""

        self.catalog = catalog
        self.catalog_json = catalog_json
        self.user = user
        self.src = src
        self.core = core
        self.loader = loader
        self.binaries = binaries if core != "" and src != "" else ""
        self.catalog_date = last_versions_dates[UpdateType.catalog.value] if catalog else ""
        self.user_date = last_versions_dates[UpdateType.user.value] if user else ""
        self.core_date = last_versions_dates[UpdateType.binaries.value] if core else ""
        self.src_date = last_versions_dates[UpdateType.binaries.value] if src else ""
        self.loader_date = last_versions_dates[UpdateType.loader.value] if loader else ""
        self.binaries_date = last_versions_dates[UpdateType.binaries.value] if core and src else ""
        self.catalog_json_date = last_versions_dates[catalog_json_value] if catalog_json else ""
        settings.check_status(self)
        self.update_control = settings.update_control
        self.menu_version = menu_version
        self.menu_name = menu_name
