# This file was auto-generated by Fern from our API Definition.

import typing
from ..core.client_wrapper import SyncClientWrapper
from ..core.request_options import RequestOptions
from .types.add_knowledge_base_document_response import AddKnowledgeBaseDocumentResponse
from ..core.pydantic_utilities import parse_obj_as
from ..transcribe.errors.authentication_error import AuthenticationError
from ..transcribe.errors.rate_limit_error import RateLimitError
from json.decoder import JSONDecodeError
from ..core.api_error import ApiError
from .types.remove_knowledge_base_document_response import RemoveKnowledgeBaseDocumentResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.client_wrapper import AsyncClientWrapper

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class MaishivClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def add_to_knowledge_base(
        self, *, document_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> AddKnowledgeBaseDocumentResponse:
        """
        Add a document to the knowledge base.

        Parameters
        ----------
        document_id : str
            ID of the document to add to the knowledge base.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AddKnowledgeBaseDocumentResponse

        Examples
        --------
        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.maishiv.add_to_knowledge_base(
            document_id="document_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/maishiv/knowledge-base",
            method="POST",
            json={
                "document_id": document_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    AddKnowledgeBaseDocumentResponse,
                    parse_obj_as(
                        type_=AddKnowledgeBaseDocumentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise AuthenticationError()
            if _response.status_code == 429:
                raise RateLimitError()
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def list_knowledge_base_docs(self, *, request_options: typing.Optional[RequestOptions] = None) -> typing.List[str]:
        """
        Get all document IDs currently in the knowledge base.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[str]

        Examples
        --------
        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.maishiv.list_knowledge_base_docs()
        """
        _response = self._client_wrapper.httpx_client.request(
            "v1/maishiv/knowledge-base",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[str],
                    parse_obj_as(
                        type_=typing.List[str],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise AuthenticationError()
            if _response.status_code == 429:
                raise RateLimitError()
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    def remove_from_knowledge_base(
        self, document_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RemoveKnowledgeBaseDocumentResponse:
        """
        Remove a document from the knowledge base.

        Parameters
        ----------
        document_id : str
            ID of the document to remove from the knowledge base.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        RemoveKnowledgeBaseDocumentResponse

        Examples
        --------
        from soferai import SoferAI

        client = SoferAI(
            api_key="YOUR_API_KEY",
        )
        client.maishiv.remove_from_knowledge_base(
            document_id="document_id",
        )
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/maishiv/knowledge-base/{jsonable_encoder(document_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    RemoveKnowledgeBaseDocumentResponse,
                    parse_obj_as(
                        type_=RemoveKnowledgeBaseDocumentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise AuthenticationError()
            if _response.status_code == 429:
                raise RateLimitError()
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)


class AsyncMaishivClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def add_to_knowledge_base(
        self, *, document_id: str, request_options: typing.Optional[RequestOptions] = None
    ) -> AddKnowledgeBaseDocumentResponse:
        """
        Add a document to the knowledge base.

        Parameters
        ----------
        document_id : str
            ID of the document to add to the knowledge base.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AddKnowledgeBaseDocumentResponse

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.maishiv.add_to_knowledge_base(
                document_id="document_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/maishiv/knowledge-base",
            method="POST",
            json={
                "document_id": document_id,
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    AddKnowledgeBaseDocumentResponse,
                    parse_obj_as(
                        type_=AddKnowledgeBaseDocumentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise AuthenticationError()
            if _response.status_code == 429:
                raise RateLimitError()
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def list_knowledge_base_docs(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[str]:
        """
        Get all document IDs currently in the knowledge base.

        Parameters
        ----------
        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.List[str]

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.maishiv.list_knowledge_base_docs()


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            "v1/maishiv/knowledge-base",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    typing.List[str],
                    parse_obj_as(
                        type_=typing.List[str],  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise AuthenticationError()
            if _response.status_code == 429:
                raise RateLimitError()
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)

    async def remove_from_knowledge_base(
        self, document_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> RemoveKnowledgeBaseDocumentResponse:
        """
        Remove a document from the knowledge base.

        Parameters
        ----------
        document_id : str
            ID of the document to remove from the knowledge base.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        RemoveKnowledgeBaseDocumentResponse

        Examples
        --------
        import asyncio

        from soferai import AsyncSoferAI

        client = AsyncSoferAI(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.maishiv.remove_from_knowledge_base(
                document_id="document_id",
            )


        asyncio.run(main())
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/maishiv/knowledge-base/{jsonable_encoder(document_id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return typing.cast(
                    RemoveKnowledgeBaseDocumentResponse,
                    parse_obj_as(
                        type_=RemoveKnowledgeBaseDocumentResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
            if _response.status_code == 401:
                raise AuthenticationError()
            if _response.status_code == 429:
                raise RateLimitError()
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, body=_response.text)
        raise ApiError(status_code=_response.status_code, body=_response_json)
