'''
Author: your name
Date: 2021-07-15 09:33:39
LastEditTime: 2021-07-22 18:54:43
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\build_out\views\package.20210715165358.py
'''
from flask import current_app, jsonify, request
from flask_restful import Resource
from flask_restful.reqparse import RequestParser
from flask_jwt_extended import (jwt_required, get_jwt_identity)
from application.signal_manager import signalManager
from webcreator.log import logger
from webcreator.response import ResponseCode, response_result


class MenuResourceList(Resource):
    def __init__(self):
        pass
        # 特殊参数，即不是从json获取参数的接口，可以将这个注释打开
        self.parser = RequestParser()

    def get(self):
        # 特殊参数，即不是从json获取参数的接口，可以将这个注释打开
        # self.parser.add_argument("page", type=int, location="args", default=1)
        # self.parser.add_argument("pageSize", type=int, location="args", default=15)
        # args = self.parser.parse_args()
        result = [
            {
                "id": "1044886626813353984",
                "parentId": "0",
                "name": "dashboard",
                "path": "/dashboard",
                "icon": "dashboard",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "analysis",
                        "path": "/dashboard/analysis",
                        "leaf": True,
                        "children": []
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "workplace",
                        "path": "/dashboard/workplace",
                        "leaf": True,
                        "children": []
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "parentId": "0",
                "name": "system",
                "path": "/system",
                "icon": "setting",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "setting",
                        "path": "/system/setting",
                        "leaf": False,
                        "children": [
                            {
                                "id": "1044886630026190848",
                                "parentId": "1044886629921333248",
                                "name": "menu",
                                "path": "/system/setting/menu",
                                "leaf": True,
                                "children": []
                            },
                            {
                                "id": "1044886630122659840",
                                "parentId": "1044886629921333248",
                                "name": "module",
                                "path": "/system/setting/module",
                                "leaf": True,
                                "children": []
                            },
                            {
                                "id": "1044886630122659841",
                                "parentId": "1044886629921333248",
                                "name": "file-manager",
                                "path": "/system/setting/file-manager",
                                "leaf": True,
                                "children": []
                            }
                        ]
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "role",
                        "path": "/system/role",
                        "leaf": True
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "admin",
                        "path": "/system/admin",
                        "leaf": True
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "icon": "shop",
                "parentId": "0",
                "name": "application",
                "path": "/application",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "index",
                        "path": "/application/index",
                        "leaf": True,
                        "children": []
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "manager",
                        "path": "/application/manager",
                        "leaf": True,
                        "children": []
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "icon": "usb",
                "parentId": "0",
                "name": "device",
                "path": "/device",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "index",
                        "path": "/device/index",
                        "leaf": True,
                        "children": []
                    }
                ]
            },
            {
                "id": "1044886626813353984",
                "icon": "tool",
                "parentId": "0",
                "name": "tools",
                "path": "/tools",
                "leaf": False,
                "children": [
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "monitor",
                        "path": "/tools/monitor",
                        "leaf": True,
                        "children": []
                    },
                    {
                        "id": "1044886629921333248",
                        "parentId": "1044886626813353984",
                        "name": "index",
                        "path": "/tools/index",
                        "leaf": True,
                        "children": []
                    }
                ]
            }
        ]
        return response_result(ResponseCode.HTTP_SUCCESS, data=result)


    def post(self):
        try:
            json_payload = request.json
            logger.warn(json_payload)
            return response_result(ResponseCode.HTTP_INVAILD_REQUEST)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)

class MenuResource(Resource):
    def __init__(self):
        pass
        # 特殊参数，即不是从json获取参数的接口，可以将这个注释打开
        # self.parser = RequestParser()

    @jwt_required(locations=["headers"])
    def get(self, uuid):
        # 特殊参数，即不是从json获取参数的接口，可以将这个注释打开
        # self.parser.add_argument("page", type=int, location="args", default=1)
        # self.parser.add_argument("pageSize", type=int, location="args", default=15)
        # args = self.parser.parse_args()

        try:
            json_payload = request.json
            print("========>", uuid, json_payload)
            return response_result(ResponseCode.HTTP_NOT_FOUND)
        except Exception as e:
            current_app.logger.error(e)
            return response_result(ResponseCode.HTTP_SERVER_ERROR)
