import base64
import json

import requests
from loguru import logger


class YdmVerify(object):
    _custom_url = "https://www.jfbym.com/api/YmServer/customApi"
    _token = "2HNCDBee_JFmXAZZanQm9I7x1sqQln9BggF1xaGtMX0"
    _headers = {
        'Content-Type': 'application/json'
    }

    def rotate(self, image):
        payload = {
            "image": base64.b64encode(image).decode(),
            "token": self._token,
            "type": "90009"
        }
        resp = requests.post(self._custom_url, headers=self._headers, data=json.dumps(payload))
        logger.debug(f"{resp.json()=}")

        response_data = resp.json()
        if response_data.get("code") == 10002:
            logger.error(f'{response_data.get("msg")}')
            return None

        return resp.json()['data']['data']