# 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.department_member_response import DepartmentMemberResponse
from ..types.department_response import DepartmentResponse
from ..types.department_tree_response import DepartmentTreeResponse
from .raw_client import AsyncRawDepartmentsClient, RawDepartmentsClient

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


class DepartmentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawDepartmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawDepartmentsClient
        """
        return self._raw_client

    def get_department_tree(
        self,
        organization_id: str,
        *,
        scope: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[DepartmentTreeResponse]:
        """
        Return nested department hierarchy.

        Parameters
        ----------
        organization_id : str

        scope : typing.Optional[str]
            Comma-separated dept IDs

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

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

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.get_department_tree(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.get_department_tree(organization_id, scope=scope, request_options=request_options)
        return _response.data

    def list_departments(
        self, organization_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DepartmentResponse]:
        """
        Return flat list of departments.

        Parameters
        ----------
        organization_id : str

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

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

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.list_departments(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.list_departments(organization_id, request_options=request_options)
        return _response.data

    def create_department(
        self,
        organization_id: str,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        parent_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentResponse:
        """
        Create a new department.

        Parameters
        ----------
        organization_id : str

        name : str

        description : typing.Optional[str]

        parent_id : typing.Optional[str]

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.create_department(
            organization_id="organization_id",
            name="name",
        )
        """
        _response = self._raw_client.create_department(
            organization_id, name=name, description=description, parent_id=parent_id, request_options=request_options
        )
        return _response.data

    def get_department(
        self, organization_id: str, department_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DepartmentResponse:
        """
        Return a single department.

        Parameters
        ----------
        organization_id : str

        department_id : str

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.get_department(
            organization_id="organization_id",
            department_id="department_id",
        )
        """
        _response = self._raw_client.get_department(organization_id, department_id, request_options=request_options)
        return _response.data

    def delete_department(
        self, organization_id: str, department_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a department (must have no children or members).

        Parameters
        ----------
        organization_id : str

        department_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.delete_department(
            organization_id="organization_id",
            department_id="department_id",
        )
        """
        _response = self._raw_client.delete_department(organization_id, department_id, request_options=request_options)
        return _response.data

    def update_department(
        self,
        organization_id: str,
        department_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentResponse:
        """
        Update department name/description.

        Parameters
        ----------
        organization_id : str

        department_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.update_department(
            organization_id="organization_id",
            department_id="department_id",
        )
        """
        _response = self._raw_client.update_department(
            organization_id, department_id, name=name, description=description, request_options=request_options
        )
        return _response.data

    def reparent_department(
        self,
        organization_id: str,
        department_id: str,
        *,
        new_parent_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentResponse:
        """
        Move department to a new parent or top-level.

        Parameters
        ----------
        organization_id : str

        department_id : str

        new_parent_id : typing.Optional[str]

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.reparent_department(
            organization_id="organization_id",
            department_id="department_id",
        )
        """
        _response = self._raw_client.reparent_department(
            organization_id, department_id, new_parent_id=new_parent_id, request_options=request_options
        )
        return _response.data

    def list_department_members(
        self, organization_id: str, department_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DepartmentMemberResponse]:
        """
        List all members of a department.

        Parameters
        ----------
        organization_id : str

        department_id : str

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

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

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.list_department_members(
            organization_id="organization_id",
            department_id="department_id",
        )
        """
        _response = self._raw_client.list_department_members(
            organization_id, department_id, request_options=request_options
        )
        return _response.data

    def add_department_member(
        self,
        organization_id: str,
        department_id: str,
        *,
        user_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentMemberResponse:
        """
        Add a user to a department.

        Parameters
        ----------
        organization_id : str

        department_id : str

        user_id : str

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

        Returns
        -------
        DepartmentMemberResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.add_department_member(
            organization_id="organization_id",
            department_id="department_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.add_department_member(
            organization_id, department_id, user_id=user_id, request_options=request_options
        )
        return _response.data

    def remove_department_member(
        self,
        organization_id: str,
        department_id: str,
        user_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Remove a user from a department.

        Parameters
        ----------
        organization_id : str

        department_id : str

        user_id : str

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

        Returns
        -------
        None

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.departments.remove_department_member(
            organization_id="organization_id",
            department_id="department_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.remove_department_member(
            organization_id, department_id, user_id, request_options=request_options
        )
        return _response.data


class AsyncDepartmentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawDepartmentsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawDepartmentsClient
        """
        return self._raw_client

    async def get_department_tree(
        self,
        organization_id: str,
        *,
        scope: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.List[DepartmentTreeResponse]:
        """
        Return nested department hierarchy.

        Parameters
        ----------
        organization_id : str

        scope : typing.Optional[str]
            Comma-separated dept IDs

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

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

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.get_department_tree(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_department_tree(
            organization_id, scope=scope, request_options=request_options
        )
        return _response.data

    async def list_departments(
        self, organization_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DepartmentResponse]:
        """
        Return flat list of departments.

        Parameters
        ----------
        organization_id : str

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

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

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.list_departments(
                organization_id="organization_id",
            )


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

    async def create_department(
        self,
        organization_id: str,
        *,
        name: str,
        description: typing.Optional[str] = OMIT,
        parent_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentResponse:
        """
        Create a new department.

        Parameters
        ----------
        organization_id : str

        name : str

        description : typing.Optional[str]

        parent_id : typing.Optional[str]

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.create_department(
                organization_id="organization_id",
                name="name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_department(
            organization_id, name=name, description=description, parent_id=parent_id, request_options=request_options
        )
        return _response.data

    async def get_department(
        self, organization_id: str, department_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DepartmentResponse:
        """
        Return a single department.

        Parameters
        ----------
        organization_id : str

        department_id : str

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.get_department(
                organization_id="organization_id",
                department_id="department_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_department(
            organization_id, department_id, request_options=request_options
        )
        return _response.data

    async def delete_department(
        self, organization_id: str, department_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> None:
        """
        Delete a department (must have no children or members).

        Parameters
        ----------
        organization_id : str

        department_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.delete_department(
                organization_id="organization_id",
                department_id="department_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_department(
            organization_id, department_id, request_options=request_options
        )
        return _response.data

    async def update_department(
        self,
        organization_id: str,
        department_id: str,
        *,
        name: typing.Optional[str] = OMIT,
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentResponse:
        """
        Update department name/description.

        Parameters
        ----------
        organization_id : str

        department_id : str

        name : typing.Optional[str]

        description : typing.Optional[str]

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.update_department(
                organization_id="organization_id",
                department_id="department_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_department(
            organization_id, department_id, name=name, description=description, request_options=request_options
        )
        return _response.data

    async def reparent_department(
        self,
        organization_id: str,
        department_id: str,
        *,
        new_parent_id: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentResponse:
        """
        Move department to a new parent or top-level.

        Parameters
        ----------
        organization_id : str

        department_id : str

        new_parent_id : typing.Optional[str]

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

        Returns
        -------
        DepartmentResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.reparent_department(
                organization_id="organization_id",
                department_id="department_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.reparent_department(
            organization_id, department_id, new_parent_id=new_parent_id, request_options=request_options
        )
        return _response.data

    async def list_department_members(
        self, organization_id: str, department_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[DepartmentMemberResponse]:
        """
        List all members of a department.

        Parameters
        ----------
        organization_id : str

        department_id : str

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

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

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.list_department_members(
                organization_id="organization_id",
                department_id="department_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_department_members(
            organization_id, department_id, request_options=request_options
        )
        return _response.data

    async def add_department_member(
        self,
        organization_id: str,
        department_id: str,
        *,
        user_id: str,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> DepartmentMemberResponse:
        """
        Add a user to a department.

        Parameters
        ----------
        organization_id : str

        department_id : str

        user_id : str

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

        Returns
        -------
        DepartmentMemberResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.add_department_member(
                organization_id="organization_id",
                department_id="department_id",
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.add_department_member(
            organization_id, department_id, user_id=user_id, request_options=request_options
        )
        return _response.data

    async def remove_department_member(
        self,
        organization_id: str,
        department_id: str,
        user_id: str,
        *,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Remove a user from a department.

        Parameters
        ----------
        organization_id : str

        department_id : str

        user_id : str

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.departments.remove_department_member(
                organization_id="organization_id",
                department_id="department_id",
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.remove_department_member(
            organization_id, department_id, user_id, request_options=request_options
        )
        return _response.data
