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

import typing

from ... import core
from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ...core.request_options import RequestOptions
from ...types.finetune_created_by import FinetuneCreatedBy
from ...types.finetune_visibility import FinetuneVisibility
from ...types.music_finetune_page_response_model import MusicFinetunePageResponseModel
from ...types.music_finetune_response_model import MusicFinetuneResponseModel
from .raw_client import AsyncRawFinetunesClient, RawFinetunesClient
from .types.finetunes_create_request_model_id import FinetunesCreateRequestModelId
from .types.finetunes_create_request_visibility import FinetunesCreateRequestVisibility
from .types.finetunes_list_request_sort import FinetunesListRequestSort
from .types.finetunes_list_request_sort_direction import FinetunesListRequestSortDirection
from .types.update_music_finetune_request_model_visibility import UpdateMusicFinetuneRequestModelVisibility

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


class FinetunesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawFinetunesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawFinetunesClient
        """
        return self._raw_client

    def list(
        self,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        visibility: typing.Optional[FinetuneVisibility] = None,
        created_by: typing.Optional[FinetuneCreatedBy] = None,
        sort: typing.Optional[FinetunesListRequestSort] = None,
        sort_direction: typing.Optional[FinetunesListRequestSortDirection] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MusicFinetunePageResponseModel:
        """
        List music finetunes accessible to you (your own, workspace-shared, and ElevenLabs-curated), with optional filtering, sorting, and cursor pagination.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching the next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many finetunes to return. Max 100, default 50.

        visibility : typing.Optional[FinetuneVisibility]
            Filter by visibility. 'private' returns private finetunes; 'workspace' returns workspace-shared finetunes; 'public' returns public finetunes, which are currently ElevenLabs curated finetunes. Omit to return all accessible finetunes.

        created_by : typing.Optional[FinetuneCreatedBy]
            Filter by creator. 'self' returns finetunes you created; 'workspace' returns finetunes created by workspace teammates; 'elevenlabs' returns ElevenLabs curated finetunes. Omit to return finetunes from all creators.

        sort : typing.Optional[FinetunesListRequestSort]
            Sort by field (created_at or name)

        sort_direction : typing.Optional[FinetunesListRequestSortDirection]
            Sort direction (asc or desc)

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

        Returns
        -------
        MusicFinetunePageResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.music.finetunes.list(
            cursor="cursor",
            page_size=1,
            visibility="private",
            created_by="self",
            sort="created_at",
            sort_direction="asc",
        )
        """
        _response = self._raw_client.list(
            cursor=cursor,
            page_size=page_size,
            visibility=visibility,
            created_by=created_by,
            sort=sort,
            sort_direction=sort_direction,
            request_options=request_options,
        )
        return _response.data

    def create(
        self,
        *,
        name: str,
        primary_genre: str,
        files: typing.Optional[typing.List[core.File]] = OMIT,
        tags: typing.Optional[typing.List[str]] = OMIT,
        visibility: typing.Optional[FinetunesCreateRequestVisibility] = OMIT,
        model_id: typing.Optional[FinetunesCreateRequestModelId] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MusicFinetuneResponseModel:
        """
        Create a new music finetune

        Parameters
        ----------
        name : str
            Name for the finetune (5-200 characters).

        primary_genre : str
            Primary musical genre of the finetune.

        files : typing.Optional[typing.List[core.File]]
            See core.File for more documentation

        tags : typing.Optional[typing.List[str]]
            Tags to associate with the finetune.

        visibility : typing.Optional[FinetunesCreateRequestVisibility]
            Finetune visibility. Only 'private' and 'workspace' can be set.

        model_id : typing.Optional[FinetunesCreateRequestModelId]
            The model to create a finetune for.

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.music.finetunes.create(
            name="name",
            primary_genre="primary_genre",
        )
        """
        _response = self._raw_client.create(
            name=name,
            primary_genre=primary_genre,
            files=files,
            tags=tags,
            visibility=visibility,
            model_id=model_id,
            request_options=request_options,
        )
        return _response.data

    def get(
        self, finetune_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MusicFinetuneResponseModel:
        """
        Get a music finetune.

        Parameters
        ----------
        finetune_id : str

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.music.finetunes.get(
            finetune_id="finetune_id",
        )
        """
        _response = self._raw_client.get(finetune_id, request_options=request_options)
        return _response.data

    def delete(
        self, finetune_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MusicFinetuneResponseModel:
        """
        Delete a music finetune

        Parameters
        ----------
        finetune_id : str

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.music.finetunes.delete(
            finetune_id="finetune_id",
        )
        """
        _response = self._raw_client.delete(finetune_id, request_options=request_options)
        return _response.data

    def update(
        self,
        finetune_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        primary_genre: typing.Optional[str] = OMIT,
        visibility: typing.Optional[UpdateMusicFinetuneRequestModelVisibility] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MusicFinetuneResponseModel:
        """
        Update a music finetune.

        Parameters
        ----------
        finetune_id : str

        name : typing.Optional[str]
            Updated name for the finetune.

        tags : typing.Optional[typing.Sequence[str]]
            Replacement set of tags.

        primary_genre : typing.Optional[str]
            Updated primary musical genre.

        visibility : typing.Optional[UpdateMusicFinetuneRequestModelVisibility]
            Finetune visibility. Only 'private' and 'workspace' can be set.

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        from elevenlabs import ElevenLabs

        client = ElevenLabs(
            api_key="YOUR_API_KEY",
        )
        client.music.finetunes.update(
            finetune_id="finetune_id",
        )
        """
        _response = self._raw_client.update(
            finetune_id,
            name=name,
            tags=tags,
            primary_genre=primary_genre,
            visibility=visibility,
            request_options=request_options,
        )
        return _response.data


class AsyncFinetunesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawFinetunesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawFinetunesClient
        """
        return self._raw_client

    async def list(
        self,
        *,
        cursor: typing.Optional[str] = None,
        page_size: typing.Optional[int] = None,
        visibility: typing.Optional[FinetuneVisibility] = None,
        created_by: typing.Optional[FinetuneCreatedBy] = None,
        sort: typing.Optional[FinetunesListRequestSort] = None,
        sort_direction: typing.Optional[FinetunesListRequestSortDirection] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MusicFinetunePageResponseModel:
        """
        List music finetunes accessible to you (your own, workspace-shared, and ElevenLabs-curated), with optional filtering, sorting, and cursor pagination.

        Parameters
        ----------
        cursor : typing.Optional[str]
            Used for fetching the next page. Cursor is returned in the response.

        page_size : typing.Optional[int]
            How many finetunes to return. Max 100, default 50.

        visibility : typing.Optional[FinetuneVisibility]
            Filter by visibility. 'private' returns private finetunes; 'workspace' returns workspace-shared finetunes; 'public' returns public finetunes, which are currently ElevenLabs curated finetunes. Omit to return all accessible finetunes.

        created_by : typing.Optional[FinetuneCreatedBy]
            Filter by creator. 'self' returns finetunes you created; 'workspace' returns finetunes created by workspace teammates; 'elevenlabs' returns ElevenLabs curated finetunes. Omit to return finetunes from all creators.

        sort : typing.Optional[FinetunesListRequestSort]
            Sort by field (created_at or name)

        sort_direction : typing.Optional[FinetunesListRequestSortDirection]
            Sort direction (asc or desc)

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

        Returns
        -------
        MusicFinetunePageResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.music.finetunes.list(
                cursor="cursor",
                page_size=1,
                visibility="private",
                created_by="self",
                sort="created_at",
                sort_direction="asc",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list(
            cursor=cursor,
            page_size=page_size,
            visibility=visibility,
            created_by=created_by,
            sort=sort,
            sort_direction=sort_direction,
            request_options=request_options,
        )
        return _response.data

    async def create(
        self,
        *,
        name: str,
        primary_genre: str,
        files: typing.Optional[typing.List[core.File]] = OMIT,
        tags: typing.Optional[typing.List[str]] = OMIT,
        visibility: typing.Optional[FinetunesCreateRequestVisibility] = OMIT,
        model_id: typing.Optional[FinetunesCreateRequestModelId] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MusicFinetuneResponseModel:
        """
        Create a new music finetune

        Parameters
        ----------
        name : str
            Name for the finetune (5-200 characters).

        primary_genre : str
            Primary musical genre of the finetune.

        files : typing.Optional[typing.List[core.File]]
            See core.File for more documentation

        tags : typing.Optional[typing.List[str]]
            Tags to associate with the finetune.

        visibility : typing.Optional[FinetunesCreateRequestVisibility]
            Finetune visibility. Only 'private' and 'workspace' can be set.

        model_id : typing.Optional[FinetunesCreateRequestModelId]
            The model to create a finetune for.

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.music.finetunes.create(
                name="name",
                primary_genre="primary_genre",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name,
            primary_genre=primary_genre,
            files=files,
            tags=tags,
            visibility=visibility,
            model_id=model_id,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self, finetune_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MusicFinetuneResponseModel:
        """
        Get a music finetune.

        Parameters
        ----------
        finetune_id : str

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.music.finetunes.get(
                finetune_id="finetune_id",
            )


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

    async def delete(
        self, finetune_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> MusicFinetuneResponseModel:
        """
        Delete a music finetune

        Parameters
        ----------
        finetune_id : str

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.music.finetunes.delete(
                finetune_id="finetune_id",
            )


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

    async def update(
        self,
        finetune_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        tags: typing.Optional[typing.Sequence[str]] = OMIT,
        primary_genre: typing.Optional[str] = OMIT,
        visibility: typing.Optional[UpdateMusicFinetuneRequestModelVisibility] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> MusicFinetuneResponseModel:
        """
        Update a music finetune.

        Parameters
        ----------
        finetune_id : str

        name : typing.Optional[str]
            Updated name for the finetune.

        tags : typing.Optional[typing.Sequence[str]]
            Replacement set of tags.

        primary_genre : typing.Optional[str]
            Updated primary musical genre.

        visibility : typing.Optional[UpdateMusicFinetuneRequestModelVisibility]
            Finetune visibility. Only 'private' and 'workspace' can be set.

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

        Returns
        -------
        MusicFinetuneResponseModel
            Successful Response

        Examples
        --------
        import asyncio

        from elevenlabs import AsyncElevenLabs

        client = AsyncElevenLabs(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.music.finetunes.update(
                finetune_id="finetune_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            finetune_id,
            name=name,
            tags=tags,
            primary_genre=primary_genre,
            visibility=visibility,
            request_options=request_options,
        )
        return _response.data
