# Code generated by Lark OpenAPI.

from typing import Optional

from lark_oapi.core import JSON
from lark_oapi.core.const import UTF_8, CONTENT_TYPE, APPLICATION_JSON
from lark_oapi.core.http import Transport
from lark_oapi.core.model import Config, RequestOption, RawResponse
from lark_oapi.core.token import verify
from ..model.create_file_version_request import CreateFileVersionRequest
from ..model.create_file_version_response import CreateFileVersionResponse
from ..model.delete_file_version_request import DeleteFileVersionRequest
from ..model.delete_file_version_response import DeleteFileVersionResponse
from ..model.get_file_version_request import GetFileVersionRequest
from ..model.get_file_version_response import GetFileVersionResponse
from ..model.list_file_version_request import ListFileVersionRequest
from ..model.list_file_version_response import ListFileVersionResponse


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

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

        return response

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

        return response

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

        return response

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

        return response
