import secrets
from mimesis import Text


class SessionManager:
    def __init__(self, session):
        self.session = session
        self.text_generator = Text("en")

    def _generate_device_model(self):
        return f"{self.text_generator.word().capitalize()} {self.text_generator.word().capitalize()}"

    def _generate_system_version(self):
        return f"{self.text_generator.word().capitalize()} {secrets.randbelow(10)}.{secrets.randbelow(10)}.{secrets.randbelow(100)}"

    def _generate_app_version(self):
        return f"{self.text_generator.word().capitalize()} {self.text_generator.word().capitalize()} {secrets.randbelow(10)}.{secrets.randbelow(10)}"

    def init_session(
        self,
        device_model=None,
        system_version=None,
        app_version=None,
        lang_code="en",
        system_lang_code="en",
    ):
        self.session.device_model = (
            device_model
            or getattr(self.session, "device_model", None)
            or self._generate_device_model()
        )
        self.session.system_version = (
            system_version
            or getattr(self.session, "system_version", None)
            or self._generate_system_version()
        )
        self.session.app_version = (
            app_version
            or getattr(self.session, "app_version", None)
            or self._generate_app_version()
        )
        self.session.lang_code = lang_code
        self.session.system_lang_code = system_lang_code
        self.session.save()
