from typing import Union
from typing import List
from datetime import datetime

from .database_manager import DatabaseManager
from ..database.requests.request import Request
from .role_manager import RoleManager
from ..exceptions import RequestError


class RequestManager(DatabaseManager):

    schema = Request

    def __init__(self, database):
        self._schema = RequestManager.schema
        self.db = database

    def first(self, **kwargs) -> Union[None, List]:
        result = super().first(**kwargs)
        if not result:
            raise RequestError

        return result

    def create_request(self, user_id, user_name, object_id, reason, request_type):
        date = datetime.now()

        return self.register(
            user_id=user_id,
            user_name=user_name,
            object_id=object_id,
            date=date,
            reason=reason,
            request_type=request_type,
        )

    def set(self, request_id, status):
        self.modify({"id": request_id}, {"status": status})

from typing import Union
from typing import List
from datetime import datetime

from .database_manager import DatabaseManager
from ..database.requests.request import Request
from .role_manager import RoleManager
from ..exceptions import RequestError
from syft.core.node.domain.service import RequestStatus
from syft.core.common.uid import UID


class RequestManager(DatabaseManager):

    schema = Request

    def __init__(self, database):
        self._schema = RequestManager.schema
        self.db = database

    def first(self, **kwargs) -> Union[None, List]:
        result = super().first(**kwargs)
        if not result:
            raise RequestError

        return result

    def create_request(
        self,
        user_id,
        user_name,
        object_id,
        reason,
        request_type,
        verify_key=None,
        tags=[],
        object_type="",
    ):
        date = datetime.now()

        return self.register(
            id=str(UID().value),
            user_id=user_id,
            user_name=user_name,
            object_id=object_id,
            date=date,
            reason=reason,
            request_type=request_type,
            verify_key=verify_key,
            tags=tags,
            object_type=object_type,
        )

    def status(self, request_id):
        _req = self.first(id=request_id)
        if _req.status == "pending":
            return RequestStatus.pending
        elif _req.status == "accepted":
            return RequestStatus.Accepted
        else:
            return RequestStatus.Rejected

    def set(self, request_id, status):
        self.modify({"id": request_id}, {"status": status})

Update create_request method / Create status method
Update create_request method / Create status method

  from typing import Union
  from typing import List
  from datetime import datetime
  
  from .database_manager import DatabaseManager
  from ..database.requests.request import Request
  from .role_manager import RoleManager
  from ..exceptions import RequestError
+ from syft.core.node.domain.service import RequestStatus
+ from syft.core.common.uid import UID
  
  
  class RequestManager(DatabaseManager):
  
      schema = Request
  
      def __init__(self, database):
          self._schema = RequestManager.schema
          self.db = database
  
      def first(self, **kwargs) -> Union[None, List]:
          result = super().first(**kwargs)
          if not result:
              raise RequestError
  
          return result
  
-     def create_request(self, user_id, user_name, object_id, reason, request_type):
+     def create_request(
+         self,
+         user_id,
+         user_name,
+         object_id,
+         reason,
+         request_type,
+         verify_key=None,
+         tags=[],
+         object_type="",
+     ):
          date = datetime.now()
  
          return self.register(
+             id=str(UID().value),
              user_id=user_id,
              user_name=user_name,
              object_id=object_id,
              date=date,
              reason=reason,
              request_type=request_type,
+             verify_key=verify_key,
+             tags=tags,
+             object_type=object_type,
          )
+ 
+     def status(self, request_id):
+         _req = self.first(id=request_id)
+         if _req.status == "pending":
+             return RequestStatus.pending
+         elif _req.status == "accepted":
+             return RequestStatus.Accepted
+         else:
+             return RequestStatus.Rejected
  
      def set(self, request_id, status):
          self.modify({"id": request_id}, {"status": status})
  
Update create_request method / Create status method
## Code Before:
from typing import Union
from typing import List
from datetime import datetime

from .database_manager import DatabaseManager
from ..database.requests.request import Request
from .role_manager import RoleManager
from ..exceptions import RequestError


class RequestManager(DatabaseManager):

    schema = Request

    def __init__(self, database):
        self._schema = RequestManager.schema
        self.db = database

    def first(self, **kwargs) -> Union[None, List]:
        result = super().first(**kwargs)
        if not result:
            raise RequestError

        return result

    def create_request(self, user_id, user_name, object_id, reason, request_type):
        date = datetime.now()

        return self.register(
            user_id=user_id,
            user_name=user_name,
            object_id=object_id,
            date=date,
            reason=reason,
            request_type=request_type,
        )

    def set(self, request_id, status):
        self.modify({"id": request_id}, {"status": status})

## Instruction:
Update create_request method / Create status method
## Code After:
from typing import Union
from typing import List
from datetime import datetime

from .database_manager import DatabaseManager
from ..database.requests.request import Request
from .role_manager import RoleManager
from ..exceptions import RequestError
from syft.core.node.domain.service import RequestStatus
from syft.core.common.uid import UID


class RequestManager(DatabaseManager):

    schema = Request

    def __init__(self, database):
        self._schema = RequestManager.schema
        self.db = database

    def first(self, **kwargs) -> Union[None, List]:
        result = super().first(**kwargs)
        if not result:
            raise RequestError

        return result

    def create_request(
        self,
        user_id,
        user_name,
        object_id,
        reason,
        request_type,
        verify_key=None,
        tags=[],
        object_type="",
    ):
        date = datetime.now()

        return self.register(
            id=str(UID().value),
            user_id=user_id,
            user_name=user_name,
            object_id=object_id,
            date=date,
            reason=reason,
            request_type=request_type,
            verify_key=verify_key,
            tags=tags,
            object_type=object_type,
        )

    def status(self, request_id):
        _req = self.first(id=request_id)
        if _req.status == "pending":
            return RequestStatus.pending
        elif _req.status == "accepted":
            return RequestStatus.Accepted
        else:
            return RequestStatus.Rejected

    def set(self, request_id, status):
        self.modify({"id": request_id}, {"status": status})
