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

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..types.list_tags_response import ListTagsResponse
from ..types.tag_response import TagResponse
from ..types.tagged_object_id import TaggedObjectId

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


class RawTagsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list_tags(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[ListTagsResponse]:
        """
        Return all of the tags for an 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 **Read Tags** 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
        ----------
        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
        -------
        HttpResponse[ListTagsResponse]
            List of tags.
        """
        _response = self._client_wrapper.httpx_client.request(
            "tags",
            method="GET",
            params={
                "limit": limit,
                "after": after,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ListTagsResponse,
                    parse_obj_as(
                        type_=ListTagsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create_tag(
        self,
        *,
        name: str,
        addresses: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        assets: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        drivers: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        machines: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        parent_tag_id: typing.Optional[str] = OMIT,
        sensors: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        vehicles: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[TagResponse]:
        """
        Create a new tag for the organization. This may include up to 20,000 tagged entities.

         **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 Tags** 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
        ----------
        name : str
            Name of this tag.

        addresses : typing.Optional[typing.Sequence[TaggedObjectId]]
            The addresses that belong to this tag.

        assets : typing.Optional[typing.Sequence[TaggedObjectId]]
            The trailers, unpowered, and powered assets that belong to this tag.

        drivers : typing.Optional[typing.Sequence[TaggedObjectId]]
            The drivers that belong to this tag.

        external_ids : typing.Optional[typing.Dict[str, str]]
            The [external IDs](https://developers.samsara.com/docs/external-ids) for the given object.

        machines : typing.Optional[typing.Sequence[TaggedObjectId]]
            The machines that belong to this tag.

        parent_tag_id : typing.Optional[str]
            If this tag is part a hierarchical tag tree, this is the ID of the parent tag, otherwise this will be omitted.

        sensors : typing.Optional[typing.Sequence[TaggedObjectId]]
            The sensors that belong to this tag.

        vehicles : typing.Optional[typing.Sequence[TaggedObjectId]]
            The vehicles that belong to this tag.

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

        Returns
        -------
        HttpResponse[TagResponse]
            Newly created tag object, including the new tag ID.
        """
        _response = self._client_wrapper.httpx_client.request(
            "tags",
            method="POST",
            json={
                "addresses": addresses,
                "assets": assets,
                "drivers": drivers,
                "externalIds": external_ids,
                "machines": machines,
                "name": name,
                "parentTagId": parent_tag_id,
                "sensors": sensors,
                "vehicles": vehicles,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get_tag(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[TagResponse]:
        """
        Fetch a tag by id.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

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

        Returns
        -------
        HttpResponse[TagResponse]
            The tag corresponding to request id.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def replace_tag(
        self,
        id: str,
        *,
        addresses: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        assets: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        drivers: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        machines: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        name: typing.Optional[str] = OMIT,
        parent_tag_id: typing.Optional[str] = OMIT,
        sensors: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        vehicles: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[TagResponse]:
        """
        Update a tag with a new name and new members. This API call would replace all old members of a tag with new members specified in the request body.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

        addresses : typing.Optional[typing.Sequence[TaggedObjectId]]
            The addresses that belong to this tag.

        assets : typing.Optional[typing.Sequence[TaggedObjectId]]
            The trailers, unpowered, and powered assets that belong to this tag.

        drivers : typing.Optional[typing.Sequence[TaggedObjectId]]
            The drivers that belong to this tag.

        machines : typing.Optional[typing.Sequence[TaggedObjectId]]
            The machines that belong to this tag.

        name : typing.Optional[str]
            Name of this tag.

        parent_tag_id : typing.Optional[str]
            If this tag is part a hierarchical tag tree, this is the ID of the parent tag, otherwise this will be omitted.

        sensors : typing.Optional[typing.Sequence[TaggedObjectId]]
            The sensors that belong to this tag.

        vehicles : typing.Optional[typing.Sequence[TaggedObjectId]]
            The vehicles that belong to this tag.

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

        Returns
        -------
        HttpResponse[TagResponse]
            The updated tag data.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "addresses": addresses,
                "assets": assets,
                "drivers": drivers,
                "machines": machines,
                "name": name,
                "parentTagId": parent_tag_id,
                "sensors": sensors,
                "vehicles": vehicles,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[None]:
        """
        Permanently deletes a tag.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return HttpResponse(response=_response, data=None)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def patch_tag(
        self,
        id: str,
        *,
        addresses: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        assets: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        drivers: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        machines: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        name: typing.Optional[str] = OMIT,
        parent_tag_id: typing.Optional[str] = OMIT,
        sensors: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        vehicles: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[TagResponse]:
        """
        Update an existing tag. **Note** this implementation of patch uses [the JSON merge patch](https://tools.ietf.org/html/rfc7396) proposed standard.

         This means that any fields included in the patch request will _overwrite_ fields which exist on the target resource.

         For arrays, this means any array included in the request will _replace_ the array that exists at the specified path, it will not _add_ to the existing array.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

        addresses : typing.Optional[typing.Sequence[TaggedObjectId]]
            The addresses that belong to this tag.

        assets : typing.Optional[typing.Sequence[TaggedObjectId]]
            The trailers, unpowered, and powered assets that belong to this tag.

        drivers : typing.Optional[typing.Sequence[TaggedObjectId]]
            The drivers that belong to this tag.

        external_ids : typing.Optional[typing.Dict[str, str]]
            The [external IDs](https://developers.samsara.com/docs/external-ids) for the given object.

        machines : typing.Optional[typing.Sequence[TaggedObjectId]]
            The machines that belong to this tag.

        name : typing.Optional[str]
            Name of this tag.

        parent_tag_id : typing.Optional[str]
            If this tag is part a hierarchical tag tree, this is the ID of the parent tag, otherwise this will be omitted.

        sensors : typing.Optional[typing.Sequence[TaggedObjectId]]
            The sensors that belong to this tag.

        vehicles : typing.Optional[typing.Sequence[TaggedObjectId]]
            The vehicles that belong to this tag.

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

        Returns
        -------
        HttpResponse[TagResponse]
            Returns updated tag object.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="PATCH",
            json={
                "addresses": addresses,
                "assets": assets,
                "drivers": drivers,
                "externalIds": external_ids,
                "machines": machines,
                "name": name,
                "parentTagId": parent_tag_id,
                "sensors": sensors,
                "vehicles": vehicles,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawTagsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list_tags(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[ListTagsResponse]:
        """
        Return all of the tags for an 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 **Read Tags** 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
        ----------
        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
        -------
        AsyncHttpResponse[ListTagsResponse]
            List of tags.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "tags",
            method="GET",
            params={
                "limit": limit,
                "after": after,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    ListTagsResponse,
                    parse_obj_as(
                        type_=ListTagsResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create_tag(
        self,
        *,
        name: str,
        addresses: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        assets: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        drivers: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        machines: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        parent_tag_id: typing.Optional[str] = OMIT,
        sensors: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        vehicles: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[TagResponse]:
        """
        Create a new tag for the organization. This may include up to 20,000 tagged entities.

         **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 Tags** 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
        ----------
        name : str
            Name of this tag.

        addresses : typing.Optional[typing.Sequence[TaggedObjectId]]
            The addresses that belong to this tag.

        assets : typing.Optional[typing.Sequence[TaggedObjectId]]
            The trailers, unpowered, and powered assets that belong to this tag.

        drivers : typing.Optional[typing.Sequence[TaggedObjectId]]
            The drivers that belong to this tag.

        external_ids : typing.Optional[typing.Dict[str, str]]
            The [external IDs](https://developers.samsara.com/docs/external-ids) for the given object.

        machines : typing.Optional[typing.Sequence[TaggedObjectId]]
            The machines that belong to this tag.

        parent_tag_id : typing.Optional[str]
            If this tag is part a hierarchical tag tree, this is the ID of the parent tag, otherwise this will be omitted.

        sensors : typing.Optional[typing.Sequence[TaggedObjectId]]
            The sensors that belong to this tag.

        vehicles : typing.Optional[typing.Sequence[TaggedObjectId]]
            The vehicles that belong to this tag.

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

        Returns
        -------
        AsyncHttpResponse[TagResponse]
            Newly created tag object, including the new tag ID.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "tags",
            method="POST",
            json={
                "addresses": addresses,
                "assets": assets,
                "drivers": drivers,
                "externalIds": external_ids,
                "machines": machines,
                "name": name,
                "parentTagId": parent_tag_id,
                "sensors": sensors,
                "vehicles": vehicles,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get_tag(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[TagResponse]:
        """
        Fetch a tag by id.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

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

        Returns
        -------
        AsyncHttpResponse[TagResponse]
            The tag corresponding to request id.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def replace_tag(
        self,
        id: str,
        *,
        addresses: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        assets: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        drivers: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        machines: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        name: typing.Optional[str] = OMIT,
        parent_tag_id: typing.Optional[str] = OMIT,
        sensors: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        vehicles: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[TagResponse]:
        """
        Update a tag with a new name and new members. This API call would replace all old members of a tag with new members specified in the request body.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

        addresses : typing.Optional[typing.Sequence[TaggedObjectId]]
            The addresses that belong to this tag.

        assets : typing.Optional[typing.Sequence[TaggedObjectId]]
            The trailers, unpowered, and powered assets that belong to this tag.

        drivers : typing.Optional[typing.Sequence[TaggedObjectId]]
            The drivers that belong to this tag.

        machines : typing.Optional[typing.Sequence[TaggedObjectId]]
            The machines that belong to this tag.

        name : typing.Optional[str]
            Name of this tag.

        parent_tag_id : typing.Optional[str]
            If this tag is part a hierarchical tag tree, this is the ID of the parent tag, otherwise this will be omitted.

        sensors : typing.Optional[typing.Sequence[TaggedObjectId]]
            The sensors that belong to this tag.

        vehicles : typing.Optional[typing.Sequence[TaggedObjectId]]
            The vehicles that belong to this tag.

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

        Returns
        -------
        AsyncHttpResponse[TagResponse]
            The updated tag data.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="PUT",
            json={
                "addresses": addresses,
                "assets": assets,
                "drivers": drivers,
                "machines": machines,
                "name": name,
                "parentTagId": parent_tag_id,
                "sensors": sensors,
                "vehicles": vehicles,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[None]:
        """
        Permanently deletes a tag.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="DELETE",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                return AsyncHttpResponse(response=_response, data=None)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def patch_tag(
        self,
        id: str,
        *,
        addresses: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        assets: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        drivers: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        machines: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        name: typing.Optional[str] = OMIT,
        parent_tag_id: typing.Optional[str] = OMIT,
        sensors: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        vehicles: typing.Optional[typing.Sequence[TaggedObjectId]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[TagResponse]:
        """
        Update an existing tag. **Note** this implementation of patch uses [the JSON merge patch](https://tools.ietf.org/html/rfc7396) proposed standard.

         This means that any fields included in the patch request will _overwrite_ fields which exist on the target resource.

         For arrays, this means any array included in the request will _replace_ the array that exists at the specified path, it will not _add_ to the existing array.

         **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 Tags** 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
            ID of the Tag. This can either be the Samsara-provided ID or an external ID. External IDs are customer-specified key-value pairs created in the POST or PATCH requests of this resource. To specify an external ID as part of a path parameter, use the following format: `key:value`. For example, `crmId:abc123`. Automatically populated external IDs are prefixed with `samsara.`. For example, `samsara.name:ELD-exempt`.

        addresses : typing.Optional[typing.Sequence[TaggedObjectId]]
            The addresses that belong to this tag.

        assets : typing.Optional[typing.Sequence[TaggedObjectId]]
            The trailers, unpowered, and powered assets that belong to this tag.

        drivers : typing.Optional[typing.Sequence[TaggedObjectId]]
            The drivers that belong to this tag.

        external_ids : typing.Optional[typing.Dict[str, str]]
            The [external IDs](https://developers.samsara.com/docs/external-ids) for the given object.

        machines : typing.Optional[typing.Sequence[TaggedObjectId]]
            The machines that belong to this tag.

        name : typing.Optional[str]
            Name of this tag.

        parent_tag_id : typing.Optional[str]
            If this tag is part a hierarchical tag tree, this is the ID of the parent tag, otherwise this will be omitted.

        sensors : typing.Optional[typing.Sequence[TaggedObjectId]]
            The sensors that belong to this tag.

        vehicles : typing.Optional[typing.Sequence[TaggedObjectId]]
            The vehicles that belong to this tag.

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

        Returns
        -------
        AsyncHttpResponse[TagResponse]
            Returns updated tag object.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"tags/{jsonable_encoder(id)}",
            method="PATCH",
            json={
                "addresses": addresses,
                "assets": assets,
                "drivers": drivers,
                "externalIds": external_ids,
                "machines": machines,
                "name": name,
                "parentTagId": parent_tag_id,
                "sensors": sensors,
                "vehicles": vehicles,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    TagResponse,
                    parse_obj_as(
                        type_=TagResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
