from . import proj_path
from .activation import valid_key


class LicenseInfo:
    key: str | None
    _type: str

    def __init__(self):
        self.key = None
        self._type = "evaluation"

        key_fname = proj_path / "license_key.txt"
        if not key_fname.exists():
            return

        key = key_fname.read_text(encoding="utf-8").strip()
        if not key:
            return

        if valid_key(key):
            self.key = key
            self._type = "regular"

    def is_regular(self) -> bool:
        return self._type == "regular"

    def is_evaluation(self) -> bool:
        return self._type == "evaluation"

    def mark_regular(self, key: str) -> None:
        self.key = key
        self._type = "regular"

    def display_type(self) -> str:
        return "Regular" if self.is_regular() else "Evaluation"


license_info = LicenseInfo()
