# Code generated by Lark OpenAPI.

import io
from typing import Any, Optional, Union, Dict, List, Set, IO, Callable, Type
from lark_oapi.core.const import UTF_8, CONTENT_TYPE, APPLICATION_JSON
from lark_oapi.core import JSON
from lark_oapi.core.token import verify
from lark_oapi.core.http import Transport
from lark_oapi.core.model import Config, RequestOption, RawResponse
from lark_oapi.core.utils import Files
from requests_toolbelt import MultipartEncoder
from ..model.create_app_data_asset_request import CreateAppDataAssetRequest
from ..model.create_app_data_asset_response import CreateAppDataAssetResponse
from ..model.delete_app_data_asset_request import DeleteAppDataAssetRequest
from ..model.delete_app_data_asset_response import DeleteAppDataAssetResponse
from ..model.get_app_data_asset_request import GetAppDataAssetRequest
from ..model.get_app_data_asset_response import GetAppDataAssetResponse
from ..model.list_app_data_asset_request import ListAppDataAssetRequest
from ..model.list_app_data_asset_response import ListAppDataAssetResponse
from ..model.upload_file_app_data_asset_request import UploadFileAppDataAssetRequest
from ..model.upload_file_app_data_asset_response import UploadFileAppDataAssetResponse


class AppDataAsset(object):
    def __init__(self, config: Config) -> None:
        self.config: Config = config

    def create(self, request: CreateAppDataAssetRequest,
               option: Optional[RequestOption] = None) -> CreateAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 添加 content-type
        if request.body is not None:
            option.headers[CONTENT_TYPE] = f"{APPLICATION_JSON}; charset=utf-8"

        # 发起请求
        resp: RawResponse = Transport.execute(self.config, request, option)

        # 反序列化
        response: CreateAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), CreateAppDataAssetResponse)
        response.raw = resp

        return response

    async def acreate(self, request: CreateAppDataAssetRequest,
                      option: Optional[RequestOption] = None) -> CreateAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 发起请求
        resp: RawResponse = await Transport.aexecute(self.config, request, option)

        # 反序列化
        response: CreateAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), CreateAppDataAssetResponse)
        response.raw = resp

        return response

    def delete(self, request: DeleteAppDataAssetRequest,
               option: Optional[RequestOption] = None) -> DeleteAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 添加 content-type
        if request.body is not None:
            option.headers[CONTENT_TYPE] = f"{APPLICATION_JSON}; charset=utf-8"

        # 发起请求
        resp: RawResponse = Transport.execute(self.config, request, option)

        # 反序列化
        response: DeleteAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), DeleteAppDataAssetResponse)
        response.raw = resp

        return response

    async def adelete(self, request: DeleteAppDataAssetRequest,
                      option: Optional[RequestOption] = None) -> DeleteAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 发起请求
        resp: RawResponse = await Transport.aexecute(self.config, request, option)

        # 反序列化
        response: DeleteAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), DeleteAppDataAssetResponse)
        response.raw = resp

        return response

    def get(self, request: GetAppDataAssetRequest, option: Optional[RequestOption] = None) -> GetAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 添加 content-type
        if request.body is not None:
            option.headers[CONTENT_TYPE] = f"{APPLICATION_JSON}; charset=utf-8"

        # 发起请求
        resp: RawResponse = Transport.execute(self.config, request, option)

        # 反序列化
        response: GetAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), GetAppDataAssetResponse)
        response.raw = resp

        return response

    async def aget(self, request: GetAppDataAssetRequest,
                   option: Optional[RequestOption] = None) -> GetAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 发起请求
        resp: RawResponse = await Transport.aexecute(self.config, request, option)

        # 反序列化
        response: GetAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), GetAppDataAssetResponse)
        response.raw = resp

        return response

    def list(self, request: ListAppDataAssetRequest,
             option: Optional[RequestOption] = None) -> ListAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 添加 content-type
        if request.body is not None:
            option.headers[CONTENT_TYPE] = f"{APPLICATION_JSON}; charset=utf-8"

        # 发起请求
        resp: RawResponse = Transport.execute(self.config, request, option)

        # 反序列化
        response: ListAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), ListAppDataAssetResponse)
        response.raw = resp

        return response

    async def alist(self, request: ListAppDataAssetRequest,
                    option: Optional[RequestOption] = None) -> ListAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 发起请求
        resp: RawResponse = await Transport.aexecute(self.config, request, option)

        # 反序列化
        response: ListAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8), ListAppDataAssetResponse)
        response.raw = resp

        return response

    def upload_file(self, request: UploadFileAppDataAssetRequest,
                    option: Optional[RequestOption] = None) -> UploadFileAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 添加 content-type
        if request.body is not None:
            form_data = MultipartEncoder(Files.parse_form_data(request.body))
            request.body = form_data
            option.headers[CONTENT_TYPE] = form_data.content_type

        # 发起请求
        resp: RawResponse = Transport.execute(self.config, request, option)

        # 反序列化
        response: UploadFileAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8),
                                                                  UploadFileAppDataAssetResponse)
        response.raw = resp

        return response

    async def aupload_file(self, request: UploadFileAppDataAssetRequest,
                           option: Optional[RequestOption] = None) -> UploadFileAppDataAssetResponse:
        if option is None:
            option = RequestOption()

        # 鉴权、获取 token
        verify(self.config, request, option)

        # 解析文件
        request.files = Files.extract_files(request.body)

        # 发起请求
        resp: RawResponse = await Transport.aexecute(self.config, request, option)

        # 反序列化
        response: UploadFileAppDataAssetResponse = JSON.unmarshal(str(resp.content, UTF_8),
                                                                  UploadFileAppDataAssetResponse)
        response.raw = resp

        return response
