# 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.attribute_expanded_response import AttributeExpandedResponse
from ..types.create_attribute_request_entities import CreateAttributeRequestEntities
from ..types.get_attributes_by_entity_type_response import GetAttributesByEntityTypeResponse
from .raw_client import AsyncRawAttributesClient, RawAttributesClient
from .types.create_attribute_request_attribute_type import CreateAttributeRequestAttributeType
from .types.create_attribute_request_entity_type import CreateAttributeRequestEntityType
from .types.create_attribute_request_unit import CreateAttributeRequestUnit
from .types.delete_attributes_request_entity_type import DeleteAttributesRequestEntityType
from .types.get_attribute_request_entity_type import GetAttributeRequestEntityType
from .types.get_attributes_by_entity_type_request_entity_type import GetAttributesByEntityTypeRequestEntityType
from .types.update_attribute_request_attribute_type import UpdateAttributeRequestAttributeType
from .types.update_attribute_request_entity_type import UpdateAttributeRequestEntityType

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


class AttributesClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAttributesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAttributesClient
        """
        return self._raw_client

    def get_attributes_by_entity_type(
        self,
        *,
        entity_type: GetAttributesByEntityTypeRequestEntityType,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetAttributesByEntityTypeResponse:
        """
        Fetch all attributes in an organization associated with either drivers or assets.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        entity_type : GetAttributesByEntityTypeRequestEntityType
            Denotes the type of entity, driver or asset.

        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        after : typing.Optional[str]
            If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        GetAttributesByEntityTypeResponse
            All attributes in an organization for an entity type

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.attributes.get_attributes_by_entity_type(
            entity_type="driver",
        )
        """
        _response = self._raw_client.get_attributes_by_entity_type(
            entity_type=entity_type, limit=limit, after=after, request_options=request_options
        )
        return _response.data

    def create_attribute(
        self,
        *,
        attribute_type: CreateAttributeRequestAttributeType,
        entity_type: CreateAttributeRequestEntityType,
        name: str,
        entities: typing.Optional[typing.Sequence[CreateAttributeRequestEntities]] = OMIT,
        number_values: typing.Optional[typing.Sequence[float]] = OMIT,
        string_values: typing.Optional[typing.Sequence[str]] = OMIT,
        unit: typing.Optional[CreateAttributeRequestUnit] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttributeExpandedResponse:
        """
        Creates a new attribute in the organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        attribute_type : CreateAttributeRequestAttributeType
            Denotes the data type of the attribute's values. Valid values: `single-select`, `multi-select`, `text`, `freeform-multi-select`, `number`, `date`.

        entity_type : CreateAttributeRequestEntityType
            Denotes the type of entity, driver or asset.

        name : str
            Name

        entities : typing.Optional[typing.Sequence[CreateAttributeRequestEntities]]
            Entities that will be applied to this attribute

        number_values : typing.Optional[typing.Sequence[float]]
            Number values that can be associated with this attribute

        string_values : typing.Optional[typing.Sequence[str]]
            String values that can be associated with this attribute

        unit : typing.Optional[CreateAttributeRequestUnit]
            Unit of the attribute (only for Number attributes).

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

        Returns
        -------
        AttributeExpandedResponse
            Newly created attribute object with ID.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.attributes.create_attribute(
            attribute_type="single-select",
            entity_type="driver",
            name="License Certifications",
        )
        """
        _response = self._raw_client.create_attribute(
            attribute_type=attribute_type,
            entity_type=entity_type,
            name=name,
            entities=entities,
            number_values=number_values,
            string_values=string_values,
            unit=unit,
            request_options=request_options,
        )
        return _response.data

    def get_attribute(
        self,
        id: str,
        *,
        entity_type: GetAttributeRequestEntityType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttributeExpandedResponse:
        """
        Fetch an attribute by id, including all of its applications.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Samsara-provided UUID of the attribute.

        entity_type : GetAttributeRequestEntityType
            Denotes the type of entity, driver or asset.

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

        Returns
        -------
        AttributeExpandedResponse
            The attribute corresponding to request id.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.attributes.get_attribute(
            id="id",
            entity_type="driver",
        )
        """
        _response = self._raw_client.get_attribute(id, entity_type=entity_type, request_options=request_options)
        return _response.data

    def delete(
        self,
        id: str,
        *,
        entity_type: DeleteAttributesRequestEntityType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete an attribute by id, including all of its applications.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Samsara-provided UUID of the attribute.

        entity_type : DeleteAttributesRequestEntityType
            Denotes the type of entity, driver or asset.

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

        Returns
        -------
        None

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.attributes.delete(
            id="id",
            entity_type="driver",
        )
        """
        _response = self._raw_client.delete(id, entity_type=entity_type, request_options=request_options)
        return _response.data

    def update_attribute(
        self,
        id: str,
        *,
        entity_type: UpdateAttributeRequestEntityType,
        attribute_type: typing.Optional[UpdateAttributeRequestAttributeType] = OMIT,
        entities: typing.Optional[typing.Sequence[CreateAttributeRequestEntities]] = OMIT,
        name: typing.Optional[str] = OMIT,
        number_values: typing.Optional[typing.Sequence[float]] = OMIT,
        string_values: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttributeExpandedResponse:
        """
        Updates an attribute in the organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Samsara-provided UUID of the attribute.

        entity_type : UpdateAttributeRequestEntityType
            Denotes the type of entity, driver or asset.

        attribute_type : typing.Optional[UpdateAttributeRequestAttributeType]
            Denotes the data type of the attribute's values. Valid values: `single-select`, `multi-select`, `text`, `freeform-multi-select`, `number`, `date`.

        entities : typing.Optional[typing.Sequence[CreateAttributeRequestEntities]]
            Entities that will be applied to this attribute

        name : typing.Optional[str]
            Name

        number_values : typing.Optional[typing.Sequence[float]]
            Number values that can be associated with this attribute

        string_values : typing.Optional[typing.Sequence[str]]
            String values that can be associated with this attribute

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

        Returns
        -------
        AttributeExpandedResponse
            Newly created attribute object with ID.

        Examples
        --------
        from samsara import Samsara

        client = Samsara(
            token="YOUR_TOKEN",
        )
        client.attributes.update_attribute(
            id="id",
            entity_type="driver",
        )
        """
        _response = self._raw_client.update_attribute(
            id,
            entity_type=entity_type,
            attribute_type=attribute_type,
            entities=entities,
            name=name,
            number_values=number_values,
            string_values=string_values,
            request_options=request_options,
        )
        return _response.data


class AsyncAttributesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAttributesClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAttributesClient
        """
        return self._raw_client

    async def get_attributes_by_entity_type(
        self,
        *,
        entity_type: GetAttributesByEntityTypeRequestEntityType,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> GetAttributesByEntityTypeResponse:
        """
        Fetch all attributes in an organization associated with either drivers or assets.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        entity_type : GetAttributesByEntityTypeRequestEntityType
            Denotes the type of entity, driver or asset.

        limit : typing.Optional[int]
            The limit for how many objects will be in the response. Default and max for this value is 512 objects.

        after : typing.Optional[str]
            If specified, this should be the endCursor value from the previous page of results. When present, this request will return the next page of results that occur immediately after the previous page of results.

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

        Returns
        -------
        GetAttributesByEntityTypeResponse
            All attributes in an organization for an entity type

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.attributes.get_attributes_by_entity_type(
                entity_type="driver",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_attributes_by_entity_type(
            entity_type=entity_type, limit=limit, after=after, request_options=request_options
        )
        return _response.data

    async def create_attribute(
        self,
        *,
        attribute_type: CreateAttributeRequestAttributeType,
        entity_type: CreateAttributeRequestEntityType,
        name: str,
        entities: typing.Optional[typing.Sequence[CreateAttributeRequestEntities]] = OMIT,
        number_values: typing.Optional[typing.Sequence[float]] = OMIT,
        string_values: typing.Optional[typing.Sequence[str]] = OMIT,
        unit: typing.Optional[CreateAttributeRequestUnit] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttributeExpandedResponse:
        """
        Creates a new attribute in the organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        attribute_type : CreateAttributeRequestAttributeType
            Denotes the data type of the attribute's values. Valid values: `single-select`, `multi-select`, `text`, `freeform-multi-select`, `number`, `date`.

        entity_type : CreateAttributeRequestEntityType
            Denotes the type of entity, driver or asset.

        name : str
            Name

        entities : typing.Optional[typing.Sequence[CreateAttributeRequestEntities]]
            Entities that will be applied to this attribute

        number_values : typing.Optional[typing.Sequence[float]]
            Number values that can be associated with this attribute

        string_values : typing.Optional[typing.Sequence[str]]
            String values that can be associated with this attribute

        unit : typing.Optional[CreateAttributeRequestUnit]
            Unit of the attribute (only for Number attributes).

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

        Returns
        -------
        AttributeExpandedResponse
            Newly created attribute object with ID.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.attributes.create_attribute(
                attribute_type="single-select",
                entity_type="driver",
                name="License Certifications",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_attribute(
            attribute_type=attribute_type,
            entity_type=entity_type,
            name=name,
            entities=entities,
            number_values=number_values,
            string_values=string_values,
            unit=unit,
            request_options=request_options,
        )
        return _response.data

    async def get_attribute(
        self,
        id: str,
        *,
        entity_type: GetAttributeRequestEntityType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttributeExpandedResponse:
        """
        Fetch an attribute by id, including all of its applications.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Read Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Samsara-provided UUID of the attribute.

        entity_type : GetAttributeRequestEntityType
            Denotes the type of entity, driver or asset.

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

        Returns
        -------
        AttributeExpandedResponse
            The attribute corresponding to request id.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.attributes.get_attribute(
                id="id",
                entity_type="driver",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_attribute(id, entity_type=entity_type, request_options=request_options)
        return _response.data

    async def delete(
        self,
        id: str,
        *,
        entity_type: DeleteAttributesRequestEntityType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> None:
        """
        Delete an attribute by id, including all of its applications.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Samsara-provided UUID of the attribute.

        entity_type : DeleteAttributesRequestEntityType
            Denotes the type of entity, driver or asset.

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

        Returns
        -------
        None

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.attributes.delete(
                id="id",
                entity_type="driver",
            )


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

    async def update_attribute(
        self,
        id: str,
        *,
        entity_type: UpdateAttributeRequestEntityType,
        attribute_type: typing.Optional[UpdateAttributeRequestAttributeType] = OMIT,
        entities: typing.Optional[typing.Sequence[CreateAttributeRequestEntities]] = OMIT,
        name: typing.Optional[str] = OMIT,
        number_values: typing.Optional[typing.Sequence[float]] = OMIT,
        string_values: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AttributeExpandedResponse:
        """
        Updates an attribute in the organization.

         **Submit Feedback**: Likes, dislikes, and API feature requests should be filed as feedback in our <a href="https://forms.gle/zkD4NCH7HjKb7mm69" target="_blank">API feedback form</a>. If you encountered an issue or noticed inaccuracies in the API documentation, please <a href="https://www.samsara.com/help" target="_blank">submit a case</a> to our support team.

        To use this endpoint, select **Write Attributes** under the Setup & Administration category when creating or editing an API token. <a href="https://developers.samsara.com/docs/authentication#scopes-for-api-tokens" target="_blank">Learn More.</a>

        Parameters
        ----------
        id : str
            Samsara-provided UUID of the attribute.

        entity_type : UpdateAttributeRequestEntityType
            Denotes the type of entity, driver or asset.

        attribute_type : typing.Optional[UpdateAttributeRequestAttributeType]
            Denotes the data type of the attribute's values. Valid values: `single-select`, `multi-select`, `text`, `freeform-multi-select`, `number`, `date`.

        entities : typing.Optional[typing.Sequence[CreateAttributeRequestEntities]]
            Entities that will be applied to this attribute

        name : typing.Optional[str]
            Name

        number_values : typing.Optional[typing.Sequence[float]]
            Number values that can be associated with this attribute

        string_values : typing.Optional[typing.Sequence[str]]
            String values that can be associated with this attribute

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

        Returns
        -------
        AttributeExpandedResponse
            Newly created attribute object with ID.

        Examples
        --------
        import asyncio

        from samsara import AsyncSamsara

        client = AsyncSamsara(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.attributes.update_attribute(
                id="id",
                entity_type="driver",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_attribute(
            id,
            entity_type=entity_type,
            attribute_type=attribute_type,
            entities=entities,
            name=name,
            number_values=number_values,
            string_values=string_values,
            request_options=request_options,
        )
        return _response.data
