import json
from typing import Any, Iterable, List, Union

from xima_ai.api_resources.apis.api_resource import APIResource, AsyncAPIResource
from xima_ai.api_resources.client import AsyncPortkey, XimaAi
from xima_ai.api_resources.types.moderations_type import ModerationCreateResponse

from ..._vendor.openai._types import Omit, omit


class Moderations(APIResource):
    def __init__(self, client: XimaAi) -> None:
        super().__init__(client)
        self.openai_client = client.openai_client

    def create(
        self,
        *,
        input: Union[str, List[str], Iterable[Any]],
        model: Union[str, Omit] = omit,
        **kwargs,
    ) -> ModerationCreateResponse:
        response = self.openai_client.with_raw_response.moderations.create(
            input=input, model=model, extra_body=kwargs
        )
        data = ModerationCreateResponse(**json.loads(response.text))
        data._headers = response.headers

        return data


class AsyncModerations(AsyncAPIResource):
    def __init__(self, client: AsyncPortkey) -> None:
        super().__init__(client)
        self.openai_client = client.openai_client

    async def create(
        self,
        *,
        input: Union[str, List[str], Iterable[Any]],
        model: Union[str, Omit] = omit,
        **kwargs,
    ) -> ModerationCreateResponse:
        response = await self.openai_client.with_raw_response.moderations.create(
            input=input, model=model, extra_body=kwargs
        )
        data = ModerationCreateResponse(**json.loads(response.text))
        data._headers = response.headers

        return data
