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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.create_project_setup_out import CreateProjectSetupOut
from ..types.get_create_project_setup_response import GetCreateProjectSetupResponse
from ..types.languages import Languages
from .raw_client import AsyncRawProjectSetupClient, RawProjectSetupClient

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


class ProjectSetupClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawProjectSetupClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawProjectSetupClient
        """
        return self._raw_client

    def create_project(
        self,
        *,
        media_url: str,
        source_language: Languages,
        target_languages: typing.Sequence[Languages],
        run_id: typing.Optional[int] = None,
        project_name: typing.Optional[str] = OMIT,
        project_description: typing.Optional[str] = OMIT,
        folder_id: typing.Optional[int] = OMIT,
        selected_audio_tracks: typing.Optional[typing.Sequence[int]] = OMIT,
        add_output_as_an_audio_track: typing.Optional[bool] = OMIT,
        chosen_dictionaries: typing.Optional[typing.Sequence[int]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateProjectSetupOut:
        """
        Creates a new project setup with transcription capabilities.

        This endpoint allows users to create a new project by providing media content
        (either as a file upload or URL), specifying source and target languages, and
        other project metadata. The function validates inputs, checks file size limitations,
        and initiates the project setup process.

        Args:
            request_payload (CreateProjectSetupRequestPayload): Complete project configuration
                    including media URL, source/target languages, project metadata, and
                    processing preferences such as audio track selection and dictionary choices.
                api_key_obj_and_subscription: Dependency injection providing validated API key
                    object and associated subscription details for authorization and usage
                    limit enforcement.
                traceparent (str | None, optional): OpenTelemetry trace parent header for
                    distributed tracing across microservices. Enables request correlation
                    and performance monitoring throughout the processing pipeline.

        Returns:
            Project setup response with project details and processing status.

        Raises:
            HTTPException:
                - 400: If neither media_file nor media_url is provided
                - 400: If uploaded file has no filename
                - 413: If uploaded file exceeds size limit

        Parameters
        ----------
        media_url : str

        source_language : Languages

        target_languages : typing.Sequence[Languages]

        run_id : typing.Optional[int]

        project_name : typing.Optional[str]

        project_description : typing.Optional[str]

        folder_id : typing.Optional[int]

        selected_audio_tracks : typing.Optional[typing.Sequence[int]]

        add_output_as_an_audio_track : typing.Optional[bool]

        chosen_dictionaries : typing.Optional[typing.Sequence[int]]

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

        Returns
        -------
        CreateProjectSetupOut
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.project_setup.create_project(
            media_url="media_url",
            source_language=1,
            target_languages=[1],
        )
        """
        _response = self._raw_client.create_project(
            media_url=media_url,
            source_language=source_language,
            target_languages=target_languages,
            run_id=run_id,
            project_name=project_name,
            project_description=project_description,
            folder_id=folder_id,
            selected_audio_tracks=selected_audio_tracks,
            add_output_as_an_audio_track=add_output_as_an_audio_track,
            chosen_dictionaries=chosen_dictionaries,
            request_options=request_options,
        )
        return _response.data

    def create_project_setup_task_status(
        self,
        task_id: str,
        *,
        run_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[GetCreateProjectSetupResponse]:
        """
        Parameters
        ----------
        task_id : str

        run_id : typing.Optional[int]

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

        Returns
        -------
        typing.List[GetCreateProjectSetupResponse]
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.project_setup.create_project_setup_task_status(
            task_id="task_id",
        )
        """
        _response = self._raw_client.create_project_setup_task_status(
            task_id, run_id=run_id, request_options=request_options
        )
        return _response.data

    def get_project_setup_result(
        self, run_id: typing.Optional[int], *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Optional[GetCreateProjectSetupResponse]:
        """
        Retrieves the final result of a completed project setup.

        This endpoint provides access to the final results of a completed project setup.
        It verifies that the authenticated user has access to the requested run_id and
        validates that the run is of the correct type (`DUB_PROJECT`) before returning results.

        Note:
            This endpoint should only be called by users to retrieve their run results via API.
            Access validation is performed to ensure users can only access their own runs.

        Args:
            run_id: Positive integer ID of the project setup run.
            api_key_obj: API key authentication data from dependency.
            traceparent: OpenTelemetry trace header for distributed tracing.

        Returns:
            GetCreateProjectSetupResponse: Project setup results including run details.

        Raises:
            HTTPException:
                - 404: If the run_id is not found
                - 400: If the run type is not valid for this endpoint (must be DUB_PROJECT)

        Parameters
        ----------
        run_id : typing.Optional[int]

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

        Returns
        -------
        typing.Optional[GetCreateProjectSetupResponse]
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.project_setup.get_project_setup_result(
            run_id=1,
        )
        """
        _response = self._raw_client.get_project_setup_result(run_id, request_options=request_options)
        return _response.data

    def get_project_setup_runs_results(
        self,
        *,
        run_ids: typing.Sequence[int],
        run_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[GetCreateProjectSetupResponse]:
        """
        Parameters
        ----------
        run_ids : typing.Sequence[int]

        run_id : typing.Optional[int]

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

        Returns
        -------
        typing.List[GetCreateProjectSetupResponse]
            Successful Response

        Examples
        --------
        from camb import CambApi

        client = CambApi(
            api_key="YOUR_API_KEY",
        )
        client.project_setup.get_project_setup_runs_results(
            run_ids=[1],
        )
        """
        _response = self._raw_client.get_project_setup_runs_results(
            run_ids=run_ids, run_id=run_id, request_options=request_options
        )
        return _response.data


class AsyncProjectSetupClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawProjectSetupClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawProjectSetupClient
        """
        return self._raw_client

    async def create_project(
        self,
        *,
        media_url: str,
        source_language: Languages,
        target_languages: typing.Sequence[Languages],
        run_id: typing.Optional[int] = None,
        project_name: typing.Optional[str] = OMIT,
        project_description: typing.Optional[str] = OMIT,
        folder_id: typing.Optional[int] = OMIT,
        selected_audio_tracks: typing.Optional[typing.Sequence[int]] = OMIT,
        add_output_as_an_audio_track: typing.Optional[bool] = OMIT,
        chosen_dictionaries: typing.Optional[typing.Sequence[int]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateProjectSetupOut:
        """
        Creates a new project setup with transcription capabilities.

        This endpoint allows users to create a new project by providing media content
        (either as a file upload or URL), specifying source and target languages, and
        other project metadata. The function validates inputs, checks file size limitations,
        and initiates the project setup process.

        Args:
            request_payload (CreateProjectSetupRequestPayload): Complete project configuration
                    including media URL, source/target languages, project metadata, and
                    processing preferences such as audio track selection and dictionary choices.
                api_key_obj_and_subscription: Dependency injection providing validated API key
                    object and associated subscription details for authorization and usage
                    limit enforcement.
                traceparent (str | None, optional): OpenTelemetry trace parent header for
                    distributed tracing across microservices. Enables request correlation
                    and performance monitoring throughout the processing pipeline.

        Returns:
            Project setup response with project details and processing status.

        Raises:
            HTTPException:
                - 400: If neither media_file nor media_url is provided
                - 400: If uploaded file has no filename
                - 413: If uploaded file exceeds size limit

        Parameters
        ----------
        media_url : str

        source_language : Languages

        target_languages : typing.Sequence[Languages]

        run_id : typing.Optional[int]

        project_name : typing.Optional[str]

        project_description : typing.Optional[str]

        folder_id : typing.Optional[int]

        selected_audio_tracks : typing.Optional[typing.Sequence[int]]

        add_output_as_an_audio_track : typing.Optional[bool]

        chosen_dictionaries : typing.Optional[typing.Sequence[int]]

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

        Returns
        -------
        CreateProjectSetupOut
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.project_setup.create_project(
                media_url="media_url",
                source_language=1,
                target_languages=[1],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_project(
            media_url=media_url,
            source_language=source_language,
            target_languages=target_languages,
            run_id=run_id,
            project_name=project_name,
            project_description=project_description,
            folder_id=folder_id,
            selected_audio_tracks=selected_audio_tracks,
            add_output_as_an_audio_track=add_output_as_an_audio_track,
            chosen_dictionaries=chosen_dictionaries,
            request_options=request_options,
        )
        return _response.data

    async def create_project_setup_task_status(
        self,
        task_id: str,
        *,
        run_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[GetCreateProjectSetupResponse]:
        """
        Parameters
        ----------
        task_id : str

        run_id : typing.Optional[int]

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

        Returns
        -------
        typing.List[GetCreateProjectSetupResponse]
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.project_setup.create_project_setup_task_status(
                task_id="task_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_project_setup_task_status(
            task_id, run_id=run_id, request_options=request_options
        )
        return _response.data

    async def get_project_setup_result(
        self, run_id: typing.Optional[int], *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Optional[GetCreateProjectSetupResponse]:
        """
        Retrieves the final result of a completed project setup.

        This endpoint provides access to the final results of a completed project setup.
        It verifies that the authenticated user has access to the requested run_id and
        validates that the run is of the correct type (`DUB_PROJECT`) before returning results.

        Note:
            This endpoint should only be called by users to retrieve their run results via API.
            Access validation is performed to ensure users can only access their own runs.

        Args:
            run_id: Positive integer ID of the project setup run.
            api_key_obj: API key authentication data from dependency.
            traceparent: OpenTelemetry trace header for distributed tracing.

        Returns:
            GetCreateProjectSetupResponse: Project setup results including run details.

        Raises:
            HTTPException:
                - 404: If the run_id is not found
                - 400: If the run type is not valid for this endpoint (must be DUB_PROJECT)

        Parameters
        ----------
        run_id : typing.Optional[int]

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

        Returns
        -------
        typing.Optional[GetCreateProjectSetupResponse]
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.project_setup.get_project_setup_result(
                run_id=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_project_setup_result(run_id, request_options=request_options)
        return _response.data

    async def get_project_setup_runs_results(
        self,
        *,
        run_ids: typing.Sequence[int],
        run_id: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[GetCreateProjectSetupResponse]:
        """
        Parameters
        ----------
        run_ids : typing.Sequence[int]

        run_id : typing.Optional[int]

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

        Returns
        -------
        typing.List[GetCreateProjectSetupResponse]
            Successful Response

        Examples
        --------
        import asyncio

        from camb import AsyncCambApi

        client = AsyncCambApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.project_setup.get_project_setup_runs_results(
                run_ids=[1],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_project_setup_runs_results(
            run_ids=run_ids, run_id=run_id, request_options=request_options
        )
        return _response.data
