# 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.request_options import RequestOptions
from ..types.change_log_list_response import ChangeLogListResponse
from .raw_client import AsyncRawCrewManagementAdminClient, RawCrewManagementAdminClient

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


class CrewManagementAdminClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawCrewManagementAdminClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawCrewManagementAdminClient
        """
        return self._raw_client

    def export_csv(
        self,
        organization_id: str,
        *,
        search_term: typing.Optional[str] = OMIT,
        role_id: typing.Optional[str] = OMIT,
        status_id: typing.Optional[str] = OMIT,
        include_deleted: typing.Optional[bool] = OMIT,
        sort_by: typing.Optional[str] = OMIT,
        sort_order: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Export organization members as CSV file.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role
        - Export limited to 10,000 records

        Args:
            organization_id: Organization ID
            request: Export filters
            db: Database session
            auth: Authenticated user

        Returns:
            CSV file as downloadable response

        Raises:
            ValidationException: If export exceeds 10,000 records

        Parameters
        ----------
        organization_id : str
            Organization ID

        search_term : typing.Optional[str]
            Search across full_name, email, and username

        role_id : typing.Optional[str]
            Filter by role ID

        status_id : typing.Optional[str]
            Filter by status ID

        include_deleted : typing.Optional[bool]
            Include soft-deleted members

        sort_by : typing.Optional[str]
            Field to sort by (full_name, email, role_name, status_name, joined_at)

        sort_order : typing.Optional[str]
            Sort order (asc or desc)

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

        Returns
        -------
        typing.Any
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.crew_management_admin.export_csv(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.export_csv(
            organization_id,
            search_term=search_term,
            role_id=role_id,
            status_id=status_id,
            include_deleted=include_deleted,
            sort_by=sort_by,
            sort_order=sort_order,
            request_options=request_options,
        )
        return _response.data

    def export_pdf(
        self,
        organization_id: str,
        *,
        search_term: typing.Optional[str] = OMIT,
        role_id: typing.Optional[str] = OMIT,
        status_id: typing.Optional[str] = OMIT,
        include_deleted: typing.Optional[bool] = OMIT,
        sort_by: typing.Optional[str] = OMIT,
        sort_order: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Export organization members as PDF file.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role
        - Export limited to 10,000 records

        Args:
            organization_id: Organization ID
            request: Export filters
            db: Database session
            auth: Authenticated user

        Returns:
            PDF file as downloadable response

        Raises:
            ValidationException: If export exceeds 10,000 records

        Parameters
        ----------
        organization_id : str
            Organization ID

        search_term : typing.Optional[str]
            Search across full_name, email, and username

        role_id : typing.Optional[str]
            Filter by role ID

        status_id : typing.Optional[str]
            Filter by status ID

        include_deleted : typing.Optional[bool]
            Include soft-deleted members

        sort_by : typing.Optional[str]
            Field to sort by (full_name, email, role_name, status_name, joined_at)

        sort_order : typing.Optional[str]
            Sort order (asc or desc)

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

        Returns
        -------
        typing.Any
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.crew_management_admin.export_pdf(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.export_pdf(
            organization_id,
            search_term=search_term,
            role_id=role_id,
            status_id=status_id,
            include_deleted=include_deleted,
            sort_by=sort_by,
            sort_order=sort_order,
            request_options=request_options,
        )
        return _response.data

    def get_organization_change_logs(
        self,
        organization_id: str,
        *,
        skip: typing.Optional[int] = OMIT,
        take: typing.Optional[int] = OMIT,
        start_date: typing.Optional[dt.datetime] = OMIT,
        end_date: typing.Optional[dt.datetime] = OMIT,
        resource_type: typing.Optional[str] = OMIT,
        action: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChangeLogListResponse:
        """
        Get paginated change logs for the organization.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role

        Args:
            organization_id: Organization ID
            request: Pagination and filter parameters
            db: Database session
            auth: Authenticated user

        Returns:
            Paginated list of audit logs for the organization

        Parameters
        ----------
        organization_id : str
            Organization ID

        skip : typing.Optional[int]
            Number of records to skip

        take : typing.Optional[int]
            Number of records to return (max 100)

        start_date : typing.Optional[dt.datetime]
            Filter logs from this date

        end_date : typing.Optional[dt.datetime]
            Filter logs until this date

        resource_type : typing.Optional[str]
            Filter by resource type (e.g., 'organization_user', 'assistant', 'rule', 'document')

        action : typing.Optional[str]
            Filter by action (e.g., 'created', 'updated', 'deleted', 'added', 'removed')

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

        Returns
        -------
        ChangeLogListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.crew_management_admin.get_organization_change_logs(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.get_organization_change_logs(
            organization_id,
            skip=skip,
            take=take,
            start_date=start_date,
            end_date=end_date,
            resource_type=resource_type,
            action=action,
            request_options=request_options,
        )
        return _response.data

    def get_member_change_logs(
        self,
        organization_id: str,
        user_id: str,
        *,
        skip: typing.Optional[int] = OMIT,
        take: typing.Optional[int] = OMIT,
        start_date: typing.Optional[dt.datetime] = OMIT,
        end_date: typing.Optional[dt.datetime] = OMIT,
        resource_type: typing.Optional[str] = OMIT,
        action: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChangeLogListResponse:
        """
        Get paginated change logs for a specific member.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role
        - Target user must exist and be a member of the organization

        Args:
            organization_id: Organization ID
            user_id: User ID to get change logs for
            request: Pagination and filter parameters
            db: Database session
            auth: Authenticated user

        Returns:
            Paginated list of audit logs for the specific member

        Raises:
            ResourceNotFoundException: If target user is not found in organization

        Parameters
        ----------
        organization_id : str
            Organization ID

        user_id : str
            User ID to get change logs for

        skip : typing.Optional[int]
            Number of records to skip

        take : typing.Optional[int]
            Number of records to return (max 100)

        start_date : typing.Optional[dt.datetime]
            Filter logs from this date

        end_date : typing.Optional[dt.datetime]
            Filter logs until this date

        resource_type : typing.Optional[str]
            Filter by resource type (e.g., 'organization_user', 'assistant', 'rule', 'document')

        action : typing.Optional[str]
            Filter by action (e.g., 'created', 'updated', 'deleted', 'added', 'removed')

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

        Returns
        -------
        ChangeLogListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.crew_management_admin.get_member_change_logs(
            organization_id="organization_id",
            user_id="user_id",
        )
        """
        _response = self._raw_client.get_member_change_logs(
            organization_id,
            user_id,
            skip=skip,
            take=take,
            start_date=start_date,
            end_date=end_date,
            resource_type=resource_type,
            action=action,
            request_options=request_options,
        )
        return _response.data


class AsyncCrewManagementAdminClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawCrewManagementAdminClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawCrewManagementAdminClient
        """
        return self._raw_client

    async def export_csv(
        self,
        organization_id: str,
        *,
        search_term: typing.Optional[str] = OMIT,
        role_id: typing.Optional[str] = OMIT,
        status_id: typing.Optional[str] = OMIT,
        include_deleted: typing.Optional[bool] = OMIT,
        sort_by: typing.Optional[str] = OMIT,
        sort_order: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Export organization members as CSV file.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role
        - Export limited to 10,000 records

        Args:
            organization_id: Organization ID
            request: Export filters
            db: Database session
            auth: Authenticated user

        Returns:
            CSV file as downloadable response

        Raises:
            ValidationException: If export exceeds 10,000 records

        Parameters
        ----------
        organization_id : str
            Organization ID

        search_term : typing.Optional[str]
            Search across full_name, email, and username

        role_id : typing.Optional[str]
            Filter by role ID

        status_id : typing.Optional[str]
            Filter by status ID

        include_deleted : typing.Optional[bool]
            Include soft-deleted members

        sort_by : typing.Optional[str]
            Field to sort by (full_name, email, role_name, status_name, joined_at)

        sort_order : typing.Optional[str]
            Sort order (asc or desc)

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

        Returns
        -------
        typing.Any
            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.crew_management_admin.export_csv(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.export_csv(
            organization_id,
            search_term=search_term,
            role_id=role_id,
            status_id=status_id,
            include_deleted=include_deleted,
            sort_by=sort_by,
            sort_order=sort_order,
            request_options=request_options,
        )
        return _response.data

    async def export_pdf(
        self,
        organization_id: str,
        *,
        search_term: typing.Optional[str] = OMIT,
        role_id: typing.Optional[str] = OMIT,
        status_id: typing.Optional[str] = OMIT,
        include_deleted: typing.Optional[bool] = OMIT,
        sort_by: typing.Optional[str] = OMIT,
        sort_order: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Any:
        """
        Export organization members as PDF file.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role
        - Export limited to 10,000 records

        Args:
            organization_id: Organization ID
            request: Export filters
            db: Database session
            auth: Authenticated user

        Returns:
            PDF file as downloadable response

        Raises:
            ValidationException: If export exceeds 10,000 records

        Parameters
        ----------
        organization_id : str
            Organization ID

        search_term : typing.Optional[str]
            Search across full_name, email, and username

        role_id : typing.Optional[str]
            Filter by role ID

        status_id : typing.Optional[str]
            Filter by status ID

        include_deleted : typing.Optional[bool]
            Include soft-deleted members

        sort_by : typing.Optional[str]
            Field to sort by (full_name, email, role_name, status_name, joined_at)

        sort_order : typing.Optional[str]
            Sort order (asc or desc)

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

        Returns
        -------
        typing.Any
            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.crew_management_admin.export_pdf(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.export_pdf(
            organization_id,
            search_term=search_term,
            role_id=role_id,
            status_id=status_id,
            include_deleted=include_deleted,
            sort_by=sort_by,
            sort_order=sort_order,
            request_options=request_options,
        )
        return _response.data

    async def get_organization_change_logs(
        self,
        organization_id: str,
        *,
        skip: typing.Optional[int] = OMIT,
        take: typing.Optional[int] = OMIT,
        start_date: typing.Optional[dt.datetime] = OMIT,
        end_date: typing.Optional[dt.datetime] = OMIT,
        resource_type: typing.Optional[str] = OMIT,
        action: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChangeLogListResponse:
        """
        Get paginated change logs for the organization.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role

        Args:
            organization_id: Organization ID
            request: Pagination and filter parameters
            db: Database session
            auth: Authenticated user

        Returns:
            Paginated list of audit logs for the organization

        Parameters
        ----------
        organization_id : str
            Organization ID

        skip : typing.Optional[int]
            Number of records to skip

        take : typing.Optional[int]
            Number of records to return (max 100)

        start_date : typing.Optional[dt.datetime]
            Filter logs from this date

        end_date : typing.Optional[dt.datetime]
            Filter logs until this date

        resource_type : typing.Optional[str]
            Filter by resource type (e.g., 'organization_user', 'assistant', 'rule', 'document')

        action : typing.Optional[str]
            Filter by action (e.g., 'created', 'updated', 'deleted', 'added', 'removed')

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

        Returns
        -------
        ChangeLogListResponse
            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.crew_management_admin.get_organization_change_logs(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_organization_change_logs(
            organization_id,
            skip=skip,
            take=take,
            start_date=start_date,
            end_date=end_date,
            resource_type=resource_type,
            action=action,
            request_options=request_options,
        )
        return _response.data

    async def get_member_change_logs(
        self,
        organization_id: str,
        user_id: str,
        *,
        skip: typing.Optional[int] = OMIT,
        take: typing.Optional[int] = OMIT,
        start_date: typing.Optional[dt.datetime] = OMIT,
        end_date: typing.Optional[dt.datetime] = OMIT,
        resource_type: typing.Optional[str] = OMIT,
        action: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ChangeLogListResponse:
        """
        Get paginated change logs for a specific member.

        Requires:
        - User must be authenticated
        - User must be a member of the organization
        - User must have Admin or Owner role
        - Target user must exist and be a member of the organization

        Args:
            organization_id: Organization ID
            user_id: User ID to get change logs for
            request: Pagination and filter parameters
            db: Database session
            auth: Authenticated user

        Returns:
            Paginated list of audit logs for the specific member

        Raises:
            ResourceNotFoundException: If target user is not found in organization

        Parameters
        ----------
        organization_id : str
            Organization ID

        user_id : str
            User ID to get change logs for

        skip : typing.Optional[int]
            Number of records to skip

        take : typing.Optional[int]
            Number of records to return (max 100)

        start_date : typing.Optional[dt.datetime]
            Filter logs from this date

        end_date : typing.Optional[dt.datetime]
            Filter logs until this date

        resource_type : typing.Optional[str]
            Filter by resource type (e.g., 'organization_user', 'assistant', 'rule', 'document')

        action : typing.Optional[str]
            Filter by action (e.g., 'created', 'updated', 'deleted', 'added', 'removed')

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

        Returns
        -------
        ChangeLogListResponse
            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.crew_management_admin.get_member_change_logs(
                organization_id="organization_id",
                user_id="user_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_member_change_logs(
            organization_id,
            user_id,
            skip=skip,
            take=take,
            start_date=start_date,
            end_date=end_date,
            resource_type=resource_type,
            action=action,
            request_options=request_options,
        )
        return _response.data
