text: from json import loads, dumps, load, dump
  from typing import Optional
  from pathlib import Path
  
  import task
  import project
  
  
  class User:
      
      def __init__(self, userid: Optional[str] = None) -> None:
          """
          Initializes a User object into runtime.
          Creates a new project when no existing user ID is specified.
  
              Parameters
                  userid (int): User ID, unique, if not given a new user is made.
          """
          with open("data/users.json", "r") as users:
              try:
                  self.__jsondata = load(users)
              except ValueError:
                  self.__jsondata = {}
          if userid:
              if not self.__jsondata.get(userid):
                  raise ValueError("User ID not found.")
              self.__userid = userid
              self.read()
          else:
              try:
                  self.__userid = str(int(max(self.__jsondata)) + 1)
              except ValueError:
                  # self.__users = '1'
                  # typfoutje __users bestaat niet moet __userid zijn
                  self.__userid = "1"
              self.__name: Optional[str] = None
              self.write()
  
      @classmethod
      def all_users_dict(cls) -> dict:
          """Classmethod that returns all users for users.json in dict"""
          with open("data/users.json", "r") as users:
              try:
                  # return loads(projects)
                  # json.loads() gaat van str naar python dict, niet van file object naar dict. json.load() werkt wel met file object.
                  return dict(load(users))
              except ValueError:
                  return {}
  
      @property
      def to_dict(self) -> dict:
          return {"userid": self.userid, "name": self.name}
  
      @to_dict.setter
      def to_dict(self, value: dict) -> None:
          self.userid = value["userid"]
          self.name = value["name"]
  
      @property
      def to_json(self) -> str:
          # return dumps(self.dict, default = str)
          # typfout, self.dict bestaat niet
          return dumps(self.to_dict, default=str)
  
      @to_json.setter
      def to_json(self, value: str) -> None:
          my_dict = loads(value)
          self.to_dict = my_dict
  
      @property
      def userid(self) -> str:
          self.read()
          return self.__userid
  
      @userid.setter
      def userid(self, value: str) -> None:
          self.__userid = value
          self.write()
  
      @property
      def name(self) -> str:
          self.read()
          return self.__name
  
      @name.setter
      def name(self, value: str) -> None:
          self.__name = value
          self.write()
  
      @property
      def tasks(self) -> list:
          """
          Returns a list of Task objects the user is part of.
          """
          return task.default_task_repo.get_tasks_by_user(self.__userid)
  
      @property
      def projects(self) -> list:
          """
          Returns a list of Project objects the user is part of
          """
          proj_list = []
          for p in project.Project.all_proj():
              if self.__userid in p.userids:
                  proj_list.append(p)
          return proj_list
  
      def read(self) -> None:
          """
          Update runtime object with contents of JSON file.
          Caution: Completely overrides runtime data with JSON data!
          """
          with open("data/users.json", "r") as users:
              try:
                  self.__jsondata = load(users)
              except ValueError:
                  self.__jsondata = {self.__userid: dict()}
  
          self.__name = self.__jsondata[self.__userid]["name"]
  
      def write(self) -> None:
          """Write runtime object state to JSON file."""
          with open("data/users.json", "r") as users:
              try:
                  self.__jsondata = load(users)
              except ValueError:
                  self.__jsondata = {self.__userid: dict()}
          if self.__userid not in self.__jsondata:
              self.__jsondata[self.__userid] = {}
  
          self.__jsondata[self.__userid]["name"] = self.__name
  
          with open("data/users.json", "w") as users:
              dump(self.__jsondata, users)
  
      @classmethod
      def createFromJson(cls, value: str) -> None:
          my_dict = loads(value)
          user = cls(my_dict["userid"], my_dict["name"])
          user.userid = my_dict["userid"]
          user.name = my_dict["name"]
  
      def __str__(self) -> str:
          return self.name
  
      def to_do(self) -> list:
          to_do = []
          for task in self.tasks:
              if task.status != "done":
                  to_do.append(task)
          return to_do
  
  
  Path(f"{Path.cwd()}/data/").mkdir(exist_ok=True)
  Path("data/users.json").touch(exist_ok=True)
  