# 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.active_custom_org_request import ActiveCustomOrgRequest
from ..model.active_custom_org_response import ActiveCustomOrgResponse
from ..model.create_custom_org_request import CreateCustomOrgRequest
from ..model.create_custom_org_response import CreateCustomOrgResponse
from ..model.delete_org_custom_org_request import DeleteOrgCustomOrgRequest
from ..model.delete_org_custom_org_response import DeleteOrgCustomOrgResponse
from ..model.patch_custom_org_request import PatchCustomOrgRequest
from ..model.patch_custom_org_response import PatchCustomOrgResponse
from ..model.query_custom_org_request import QueryCustomOrgRequest
from ..model.query_custom_org_response import QueryCustomOrgResponse
from ..model.query_recent_change_custom_org_request import QueryRecentChangeCustomOrgRequest
from ..model.query_recent_change_custom_org_response import QueryRecentChangeCustomOrgResponse
from ..model.update_rule_custom_org_request import UpdateRuleCustomOrgRequest
from ..model.update_rule_custom_org_response import UpdateRuleCustomOrgResponse


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

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

        return response

    async def aactive(self, request: ActiveCustomOrgRequest,
                      option: Optional[RequestOption] = None) -> ActiveCustomOrgResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response

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

        return response

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

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

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

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

        return response

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

        return response

    async def adelete_org(self, request: DeleteOrgCustomOrgRequest,
                          option: Optional[RequestOption] = None) -> DeleteOrgCustomOrgResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response

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

        return response

    async def apatch(self, request: PatchCustomOrgRequest,
                     option: Optional[RequestOption] = None) -> PatchCustomOrgResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response

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

        return response

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

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

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

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

        return response

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

        return response

    async def aquery_recent_change(self, request: QueryRecentChangeCustomOrgRequest,
                                   option: Optional[RequestOption] = None) -> QueryRecentChangeCustomOrgResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response

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

        return response

    async def aupdate_rule(self, request: UpdateRuleCustomOrgRequest,
                           option: Optional[RequestOption] = None) -> UpdateRuleCustomOrgResponse:
        if option is None:
            option = RequestOption()

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

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

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

        return response
