from .blueprint import setup_blueprint as setup_route
from flask import request, Response
import json
from syft.core.node.common.service.repr_service import ReprMessage

from ..auth import error_handler, token_required
from ...core.node import node


@setup_route.route("/", methods=["POST"])
# @token_required
def initial_setup():
    def route_logic():
        # Get request body
        content = loads(request.data)

        syft_message = {}
        syft_message["message_class"] = ReprMessage  # TODO: InitialSetupSettingsMessage
        syft_message["message_content"] = content
        syft_message[
            "sign_key"
        ] = node.signing_key  # TODO: Method to map token into sign-key

        # Execute task
        status_code, response_body = task_handler(
            route_function=process_as_syft_message,
            data=syft_message,
            mandatory={
                "message_class": MissingRequestKeyError,
                "message_content": MissingRequestKeyError,
                "sign_key": MissingRequestKeyError,
            },
        )
        return response_body

    # status_code, response_body = error_handler(process_as_syft_message)
    status_code, response_body = 200, {"msg": "Running initial setup!"}

    return Response(
        json.dumps(response_body), status=status_code, mimetype="application/json"
    )


@setup_route.route("/", methods=["GET"])
# @token_required
def get_setup():
    def route_logic():
        # Get request body
        content = loads(request.data)

        syft_message = {}
        syft_message["message_class"] = ReprMessage  # TODO: Get Initial Setup Messages
        syft_message["message_content"] = content
        syft_message[
            "sign_key"
        ] = node.signing_key  # TODO: Method to map token into sign-key

        # Execute task
        status_code, response_body = task_handler(
            route_function=process_as_syft_message,
            data=syft_message,
            mandatory={
                "message_class": MissingRequestKeyError,
                "message_content": MissingRequestKeyError,
                "sign_key": MissingRequestKeyError,
            },
        )
        return response_body

    # status_code, response_body = error_handler(process_as_syft_message)
    status_code, response_body = 200, {"setup": {}}

    return Response(
        json.dumps(response_body), status=status_code, mimetype="application/json"
    )

@@ -95,16 +95,17 @@
 rt json%0A
+%0A
 from syf
@@ -110,64 +110,99 @@
 yft.
-core.node.common.service.repr_service import ReprMessage
+grid.messages.setup_messages import (%0A    CreateInitialSetUpMessage,%0A    GetSetUpMessage,%0A)
 %0A%0Afr
@@ -265,24 +265,39 @@
 ore.
-node import node
+task_handler import route_logic
 %0A%0A%0A@
@@ -333,26 +333,24 @@
 s=%5B%22POST%22%5D)%0A
-# 
 @token_requi
@@ -375,42 +375,27 @@
 tup(
-):%0A    def route_logic(
+current_user
 ):%0A    
-  
-  
 # Ge
@@ -401,36 +401,32 @@
 et request body%0A
-    
     content = lo
@@ -419,38 +419,32 @@
   content = 
-loads(
 request.
 data)%0A%0A     
@@ -435,325 +435,61 @@
 est.
-data)%0A%0A        syft_message = %7B%7D%0A        syft_message%5B%22message_class%22%5D = ReprMessage  # TODO: InitialSetupSettingsMessage%0A        syft_message%5B%22message_content%22%5D = content%0A        syft_message%5B%0A            %22sign_key%22%0A        %5D = node.signing_key  # TODO: Method to map token into sign-key%0A%0A        # Execute task%0A    
+get_json()%0A    if not content:%0A        content = %7B%7D%0A%0A
     
@@ -506,35 +506,35 @@
 e, response_
-body = task
+msg = error
 _handler(%0A  
@@ -543,475 +543,164 @@
     
-    
 route_
-function=process_as_syft_message,%0A            data=syft_message,%0A            mandatory=%7B%0A                %22message_class%22: MissingRequestKeyError,%0A                %22message_content%22: MissingRequestKeyError,%0A                %22sign_key%22: MissingRequestKeyError,%0A            %7D,%0A        )%0A        return response_body%0A%0A    # status_code, response_body = error_handler(process_as_syft_message)%0A    status_code, response_body = 200, %7B%22msg%22: %22Running initial setup!%22%7D
+logic, CreateInitialSetUpMessage, current_user, content%0A    )%0A%0A    response = response_msg if isinstance(response_msg, dict) else response_msg.content
 %0A%0A  
@@ -737,39 +737,42 @@
 n.dumps(response
-_body),
+),%0A       
  status=status_c
@@ -767,32 +767,40 @@
 tus=status_code,
+%0A       
  mimetype=%22appli
@@ -807,24 +807,25 @@
 cation/json%22
+,
 %0A    )%0A%0A%0A@se
@@ -862,18 +862,16 @@
 %22GET%22%5D)%0A
-# 
 @token_r
@@ -896,38 +896,23 @@
 tup(
-):%0A    def route_logic():%0A    
+current_user):%0A
     
@@ -930,20 +930,16 @@
 st body%0A
-    
     cont
@@ -948,22 +948,16 @@
 t = 
-loads(
 request.
 data
@@ -956,324 +956,61 @@
 est.
-data)%0A%0A        syft_message = %7B%7D%0A        syft_message%5B%22message_class%22%5D = ReprMessage  # TODO: Get Initial Setup Messages%0A        syft_message%5B%22message_content%22%5D = content%0A        syft_message%5B%0A            %22sign_key%22%0A        %5D = node.signing_key  # TODO: Method to map token into sign-key%0A%0A        # Execute task%0A    
+get_json()%0A    if not content:%0A        content = %7B%7D%0A%0A
     
@@ -1035,19 +1035,19 @@
 nse_
-body = task
+msg = error
 _han
@@ -1064,455 +1064,154 @@
     
-   
- 
 route_
-function=process_as_syft_message,%0A            data=syft_message,%0A            mandatory=%7B%0A                %22message_class%22: MissingRequestKeyError,%0A                %22message_content%22: MissingRequestKeyError,%0A                %22sign_key%22: MissingRequestKeyError,%0A            %7D,%0A        )%0A        return response_body%0A%0A    # status_code, response_body = error_handler(process_as_syft_message)%0A    status_code, response_body = 200, %7B%22setup%22: %7B%7D%7D
+logic, GetSetUpMessage, current_user, content%0A    )%0A%0A    response = response_msg if isinstance(response_msg, dict) else response_msg.content
 %0A%0A  
@@ -1260,15 +1260,18 @@
 onse
-_body),
+),%0A       
  sta
@@ -1286,16 +1286,24 @@
 us_code,
+%0A       
  mimetyp
@@ -1322,15 +1322,16 @@
 on/json%22
+,
 %0A    )%0A

Update vanity api setup routes