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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.pagination import AsyncPager, SyncPager
from ..core.request_options import RequestOptions
from ..types.corpus_key import CorpusKey
from ..types.job import Job
from ..types.job_state import JobState
from .raw_client import AsyncRawJobsClient, RawJobsClient


class JobsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawJobsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawJobsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawJobsClient
        """
        return self._raw_client

    def list(
        self,
        *,
        corpus_key: typing.Optional[typing.Union[CorpusKey, typing.Sequence[CorpusKey]]] = None,
        after: typing.Optional[dt.datetime] = None,
        state: typing.Optional[typing.Union[JobState, typing.Sequence[JobState]]] = None,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Job]:
        """
        List jobs for the account. Jobs are background processes like replacing the filterable metadata attributes.

        Parameters
        ----------
        corpus_key : typing.Optional[typing.Union[CorpusKey, typing.Sequence[CorpusKey]]]
            The unique key identifying the corpus with the job.

        after : typing.Optional[dt.datetime]
            Filter by jobs created after a particular date-time.

        state : typing.Optional[typing.Union[JobState, typing.Sequence[JobState]]]
            Filter by jobs in particular states.

        limit : typing.Optional[int]
            The maximum number of jobs to return at one time.

        page_key : typing.Optional[str]
            Used to retrieve the next page of jobs after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        SyncPager[Job]
            List of jobs.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        response = client.jobs.list()
        for item in response:
            yield item
        # alternatively, you can paginate page-by-page
        for page in response.iter_pages():
            yield page
        """
        response = self._raw_client.list(
            corpus_key=corpus_key,
            after=after,
            state=state,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    def get(
        self,
        job_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Job:
        """
        Get a job by a specific ID. Jobs are background processes like replacing the filterable metadata attributes.

        Parameters
        ----------
        job_id : str
            The ID of the job to get.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        Job
            A job.

        Examples
        --------
        from vectara import Vectara
        client = Vectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        client.jobs.get(job_id='job_id', )
        """
        response = self._raw_client.get(
            job_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data


class AsyncJobsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawJobsClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawJobsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawJobsClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        corpus_key: typing.Optional[typing.Union[CorpusKey, typing.Sequence[CorpusKey]]] = None,
        after: typing.Optional[dt.datetime] = None,
        state: typing.Optional[typing.Union[JobState, typing.Sequence[JobState]]] = None,
        limit: typing.Optional[int] = None,
        page_key: typing.Optional[str] = None,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Job]:
        """
        List jobs for the account. Jobs are background processes like replacing the filterable metadata attributes.

        Parameters
        ----------
        corpus_key : typing.Optional[typing.Union[CorpusKey, typing.Sequence[CorpusKey]]]
            The unique key identifying the corpus with the job.

        after : typing.Optional[dt.datetime]
            Filter by jobs created after a particular date-time.

        state : typing.Optional[typing.Union[JobState, typing.Sequence[JobState]]]
            Filter by jobs in particular states.

        limit : typing.Optional[int]
            The maximum number of jobs to return at one time.

        page_key : typing.Optional[str]
            Used to retrieve the next page of jobs after the limit has been reached.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        AsyncPager[Job]
            List of jobs.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            response = await client.jobs.list()
            async for item in response:
                yield item

            # alternatively, you can paginate page-by-page
            async for page in response.iter_pages():
                yield page
        asyncio.run(main())
        """
        response = await self._raw_client.list(
            corpus_key=corpus_key,
            after=after,
            state=state,
            limit=limit,
            page_key=page_key,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data

    async def get(
        self,
        job_id: str,
        *,
        request_timeout: typing.Optional[int] = None,
        request_timeout_millis: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> Job:
        """
        Get a job by a specific ID. Jobs are background processes like replacing the filterable metadata attributes.

        Parameters
        ----------
        job_id : str
            The ID of the job to get.

        request_timeout : typing.Optional[int]
            The API will make a best effort to complete the request in the specified seconds or time out.

        request_timeout_millis : typing.Optional[int]
            The API will make a best effort to complete the request in the specified milliseconds or time out.

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

        Returns
        -------
        Job
            A job.

        Examples
        --------
        from vectara import AsyncVectara
        import asyncio
        client = AsyncVectara(api_key="YOUR_API_KEY", client_id="YOUR_CLIENT_ID", client_secret="YOUR_CLIENT_SECRET", )
        async def main() -> None:
            await client.jobs.get(job_id='job_id', )
        asyncio.run(main())
        """
        response = await self._raw_client.get(
            job_id,
            request_timeout=request_timeout,
            request_timeout_millis=request_timeout_millis,
            request_options=request_options,
        )
        return response.data
