# -*- encoding: utf-8 -*-
# -----------------------------------------------------------------------------
# @File Name  : template_manage.py
# @Time       : 2021/1/6 下午6:25
# @Author     : X. Peng
# @Email      : acepengxiong@163.com
# @Software   : PyCharm
# -----------------------------------------------------------------------------
import json

from flask_restful import Resource, reqparse
from flask import request

from app.api.engine import redis
from app.utils.format_transfer import npEncoder
from app.utils.jinjia2html_v2 import DataIntegrate
import numpy as np


class TemplateManage(Resource):
    """."""

    def __init__(self):
        """."""
        self.parser = reqparse.RequestParser()

    def get(self):
        """."""
        self.parser.add_argument('customer_id', type=str, required=True, help='customer_id不能为空')
        args = self.parser.parse_args()
        token = request.headers.get('Authorization', '')
        token = 's:sid:' + token.split(' ')[1]
        ifa_id = redis.get(token).decode()
        if not ifa_id:
            return {"code":40005,"data":None,"lang":"zh_CN","msg":"请登陆"}
        ifa_id = ifa_id.replace('\'', '')
        customer_id = args.get('customer_id')
        data = []
        try:
            dt = DataIntegrate(ifa_id=ifa_id, customer_id=customer_id)
            data = dt.get_template_data()
        except:
            pass
        resp = {
            "statusCode": "0000",
            "message": "成功",
            "attributes": data
        }
        return json.dumps(resp, cls=npEncoder, ensure_ascii=False)

    def post(self):
        """."""
        pass

    def put(self, id):
        """."""
        pass

    def delete(self, id):
        """."""
        pass