# -*- coding: UTF-8 -*-

from bohrium_open_sdk import OpenSDK


class App:
    def __init__(self, base_url="https://openapi.test.dp.tech", access_key="", timeout=60):
        # timeout 默认 1min
        self.client = OpenSDK(base_url=base_url, access_key=access_key, timeout=timeout)

    def get_user_info(self):
        resp = self.client.user.get_info()
        data = resp.get("data")
        return data.get("user_id"), data.get("org_id")

    def get_app_id(self, app_key):
        resp = self.client.app.get_app_info(app_key)
        return resp.get("data").get("id")

    def create(self, data):
        return self.client.app_db.create(data)

    def delete(self, data):
        return self.client.app_db.delete(data)

    def count(self, data):
        return self.client.app_db.count(data)

    def update(self, data):
        return self.client.app_db.update(data)

    def query(self, data):
        return self.client.app_db.query(data)

    def create_table(self, data):
        return self.client.app_db.create_table(data)

    def delete_table(self, data):
        return self.client.app_db.delete_table(data)
