# 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.logout_session_request import LogoutSessionRequest
from ..model.logout_session_response import LogoutSessionResponse
from ..model.query_session_request import QuerySessionRequest
from ..model.query_session_response import QuerySessionResponse


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

    def logout(self, request: LogoutSessionRequest, option: Optional[RequestOption] = None) -> LogoutSessionResponse:
        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: LogoutSessionResponse = JSON.unmarshal(str(resp.content, UTF_8), LogoutSessionResponse)
        response.raw = resp

        return response

    async def alogout(self, request: LogoutSessionRequest,
                      option: Optional[RequestOption] = None) -> LogoutSessionResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response

    def query(self, request: QuerySessionRequest, option: Optional[RequestOption] = None) -> QuerySessionResponse:
        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: QuerySessionResponse = JSON.unmarshal(str(resp.content, UTF_8), QuerySessionResponse)
        response.raw = resp

        return response

    async def aquery(self, request: QuerySessionRequest,
                     option: Optional[RequestOption] = None) -> QuerySessionResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response
