# 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.pagination import AsyncPager, SyncPager
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..types.address import Address
from ..types.address_response import AddressResponse
from ..types.create_address_request_geofence import CreateAddressRequestGeofence
from ..types.list_addresses_response import ListAddressesResponse
from ..types.update_address_request_geofence import UpdateAddressRequestGeofence
from .types.create_address_request_address_types_item import CreateAddressRequestAddressTypesItem
from .types.update_address_request_address_types_item import UpdateAddressRequestAddressTypesItem

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


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

    def list(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        parent_tag_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        tag_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        created_after_time: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> SyncPager[Address, ListAddressesResponse]:
        """
        Returns a list of all addresses in 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 Addresses** under the Addresses 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.

        parent_tag_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A filter on the data based on this comma-separated list of parent tag IDs, for use by orgs with tag hierarchies. Specifying a parent tag will implicitly include all descendent tags of the parent tag. Example: `parentTagIds=345,678`

        tag_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A filter on the data based on this comma-separated list of tag IDs. Example: `tagIds=1234,5678`

        created_after_time : typing.Optional[str]
            A filter on data to have a created at time after or equal to this specified time in RFC 3339 format. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00).

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

        Returns
        -------
        SyncPager[Address, ListAddressesResponse]
            List of all addresses in the organization
        """
        _response = self._client_wrapper.httpx_client.request(
            "addresses",
            method="GET",
            params={
                "limit": limit,
                "after": after,
                "parentTagIds": parent_tag_ids,
                "tagIds": tag_ids,
                "createdAfterTime": created_after_time,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListAddressesResponse,
                    parse_obj_as(
                        type_=ListAddressesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _items = _parsed_response.data
                _has_next = False
                _get_next = None
                if _parsed_response.pagination is not None:
                    _parsed_next = _parsed_response.pagination.end_cursor
                    _has_next = _parsed_next is not None and _parsed_next != ""
                    _get_next = lambda: self.list(
                        limit=limit,
                        after=_parsed_next,
                        parent_tag_ids=parent_tag_ids,
                        tag_ids=tag_ids,
                        created_after_time=created_after_time,
                        request_options=request_options,
                    )
                return SyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
            _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(
        self,
        *,
        formatted_address: str,
        geofence: CreateAddressRequestGeofence,
        name: str,
        address_types: typing.Optional[typing.Sequence[CreateAddressRequestAddressTypesItem]] = OMIT,
        contact_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        latitude: typing.Optional[float] = OMIT,
        longitude: typing.Optional[float] = OMIT,
        notes: typing.Optional[str] = OMIT,
        tag_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AddressResponse]:
        """
        Creates a new address 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 Addresses** under the Addresses 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
        ----------
        formatted_address : str
            The full street address for this address/geofence, as it might be recognized by Google Maps.

        geofence : CreateAddressRequestGeofence

        name : str
            Name of the address.

        address_types : typing.Optional[typing.Sequence[CreateAddressRequestAddressTypesItem]]
            Reporting location type associated with the address (used for ELD reporting purposes). Valid values: `yard`, `shortHaul`, `workforceSite`, `riskZone`, `industrialSite`, `alertsOnly`, `agricultureSource`, `avoidanceZone`, `knownGPSJammingZone`, `authorizedZone`, `unauthorizedZone`, `vendor`, `inventory`.

        contact_ids : typing.Optional[typing.Sequence[str]]
            An array of Contact IDs associated with this Address.

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

        latitude : typing.Optional[float]
            Latitude of the address. Will be geocoded from `formattedAddress` if not provided.

        longitude : typing.Optional[float]
            Longitude of the address. Will be geocoded from `formattedAddress` if not provided.

        notes : typing.Optional[str]
            Notes about the address.

        tag_ids : typing.Optional[typing.Sequence[str]]
            An array of IDs of tags to associate with this address.

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

        Returns
        -------
        HttpResponse[AddressResponse]
            Newly created address object with ID.
        """
        _response = self._client_wrapper.httpx_client.request(
            "addresses",
            method="POST",
            json={
                "addressTypes": address_types,
                "contactIds": contact_ids,
                "externalIds": external_ids,
                "formattedAddress": formatted_address,
                "geofence": convert_and_respect_annotation_metadata(
                    object_=geofence, annotation=CreateAddressRequestGeofence, direction="write"
                ),
                "latitude": latitude,
                "longitude": longitude,
                "name": name,
                "notes": notes,
                "tagIds": tag_ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddressResponse,
                    parse_obj_as(
                        type_=AddressResponse,  # 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(self, id: str, *, request_options: typing.Optional[RequestOptions] = None) -> HttpResponse[AddressResponse]:
        """
        Returns a specific address.

         **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 Addresses** under the Addresses 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 Address. 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`

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

        Returns
        -------
        HttpResponse[AddressResponse]
            An Address.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"addresses/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddressResponse,
                    parse_obj_as(
                        type_=AddressResponse,  # 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]:
        """
        Delete a specific address.

         **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 Addresses** under the Addresses 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 Address. 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`

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

        Returns
        -------
        HttpResponse[None]
        """
        _response = self._client_wrapper.httpx_client.request(
            f"addresses/{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 update(
        self,
        id: str,
        *,
        address_types: typing.Optional[typing.Sequence[UpdateAddressRequestAddressTypesItem]] = OMIT,
        contact_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        formatted_address: typing.Optional[str] = OMIT,
        geofence: typing.Optional[UpdateAddressRequestGeofence] = OMIT,
        latitude: typing.Optional[float] = OMIT,
        longitude: typing.Optional[float] = OMIT,
        name: typing.Optional[str] = OMIT,
        notes: typing.Optional[str] = OMIT,
        tag_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AddressResponse]:
        """
        Update a specific address.

         **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 Addresses** under the Addresses 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 Address. 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`

        address_types : typing.Optional[typing.Sequence[UpdateAddressRequestAddressTypesItem]]
            Reporting location type associated with the address (used for ELD reporting purposes). Valid values: `yard`, `shortHaul`, `workforceSite`, `riskZone`, `industrialSite`, `alertsOnly`, `agricultureSource`, `avoidanceZone`, `knownGPSJammingZone`, `authorizedZone`, `unauthorizedZone`, `vendor`, `inventory`.

        contact_ids : typing.Optional[typing.Sequence[str]]
            An array of Contact IDs associated with this Address.

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

        formatted_address : typing.Optional[str]
            The full street address for this address/geofence, as it might be recognized by Google Maps.

        geofence : typing.Optional[UpdateAddressRequestGeofence]

        latitude : typing.Optional[float]
            Latitude of the address. Will be geocoded from `formattedAddress` if not provided.

        longitude : typing.Optional[float]
            Longitude of the address. Will be geocoded from `formattedAddress` if not provided.

        name : typing.Optional[str]
            Name of the address.

        notes : typing.Optional[str]
            Notes about the address.

        tag_ids : typing.Optional[typing.Sequence[str]]
            An array of IDs of tags to associate with this address.

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

        Returns
        -------
        HttpResponse[AddressResponse]
            Updated address object with ID.
        """
        _response = self._client_wrapper.httpx_client.request(
            f"addresses/{jsonable_encoder(id)}",
            method="PATCH",
            json={
                "addressTypes": address_types,
                "contactIds": contact_ids,
                "externalIds": external_ids,
                "formattedAddress": formatted_address,
                "geofence": convert_and_respect_annotation_metadata(
                    object_=geofence, annotation=UpdateAddressRequestGeofence, direction="write"
                ),
                "latitude": latitude,
                "longitude": longitude,
                "name": name,
                "notes": notes,
                "tagIds": tag_ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddressResponse,
                    parse_obj_as(
                        type_=AddressResponse,  # 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 AsyncRawAddressesClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self,
        *,
        limit: typing.Optional[int] = None,
        after: typing.Optional[str] = None,
        parent_tag_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        tag_ids: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None,
        created_after_time: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncPager[Address, ListAddressesResponse]:
        """
        Returns a list of all addresses in 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 Addresses** under the Addresses 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.

        parent_tag_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A filter on the data based on this comma-separated list of parent tag IDs, for use by orgs with tag hierarchies. Specifying a parent tag will implicitly include all descendent tags of the parent tag. Example: `parentTagIds=345,678`

        tag_ids : typing.Optional[typing.Union[str, typing.Sequence[str]]]
            A filter on the data based on this comma-separated list of tag IDs. Example: `tagIds=1234,5678`

        created_after_time : typing.Optional[str]
            A filter on data to have a created at time after or equal to this specified time in RFC 3339 format. Millisecond precision and timezones are supported. (Examples: 2019-06-13T19:08:25Z, 2019-06-13T19:08:25.455Z, OR 2015-09-15T14:00:12-04:00).

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

        Returns
        -------
        AsyncPager[Address, ListAddressesResponse]
            List of all addresses in the organization
        """
        _response = await self._client_wrapper.httpx_client.request(
            "addresses",
            method="GET",
            params={
                "limit": limit,
                "after": after,
                "parentTagIds": parent_tag_ids,
                "tagIds": tag_ids,
                "createdAfterTime": created_after_time,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _parsed_response = typing.cast(
                    ListAddressesResponse,
                    parse_obj_as(
                        type_=ListAddressesResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                _items = _parsed_response.data
                _has_next = False
                _get_next = None
                if _parsed_response.pagination is not None:
                    _parsed_next = _parsed_response.pagination.end_cursor
                    _has_next = _parsed_next is not None and _parsed_next != ""

                    async def _get_next():
                        return await self.list(
                            limit=limit,
                            after=_parsed_next,
                            parent_tag_ids=parent_tag_ids,
                            tag_ids=tag_ids,
                            created_after_time=created_after_time,
                            request_options=request_options,
                        )

                return AsyncPager(has_next=_has_next, items=_items, get_next=_get_next, response=_parsed_response)
            _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(
        self,
        *,
        formatted_address: str,
        geofence: CreateAddressRequestGeofence,
        name: str,
        address_types: typing.Optional[typing.Sequence[CreateAddressRequestAddressTypesItem]] = OMIT,
        contact_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        latitude: typing.Optional[float] = OMIT,
        longitude: typing.Optional[float] = OMIT,
        notes: typing.Optional[str] = OMIT,
        tag_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AddressResponse]:
        """
        Creates a new address 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 Addresses** under the Addresses 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
        ----------
        formatted_address : str
            The full street address for this address/geofence, as it might be recognized by Google Maps.

        geofence : CreateAddressRequestGeofence

        name : str
            Name of the address.

        address_types : typing.Optional[typing.Sequence[CreateAddressRequestAddressTypesItem]]
            Reporting location type associated with the address (used for ELD reporting purposes). Valid values: `yard`, `shortHaul`, `workforceSite`, `riskZone`, `industrialSite`, `alertsOnly`, `agricultureSource`, `avoidanceZone`, `knownGPSJammingZone`, `authorizedZone`, `unauthorizedZone`, `vendor`, `inventory`.

        contact_ids : typing.Optional[typing.Sequence[str]]
            An array of Contact IDs associated with this Address.

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

        latitude : typing.Optional[float]
            Latitude of the address. Will be geocoded from `formattedAddress` if not provided.

        longitude : typing.Optional[float]
            Longitude of the address. Will be geocoded from `formattedAddress` if not provided.

        notes : typing.Optional[str]
            Notes about the address.

        tag_ids : typing.Optional[typing.Sequence[str]]
            An array of IDs of tags to associate with this address.

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

        Returns
        -------
        AsyncHttpResponse[AddressResponse]
            Newly created address object with ID.
        """
        _response = await self._client_wrapper.httpx_client.request(
            "addresses",
            method="POST",
            json={
                "addressTypes": address_types,
                "contactIds": contact_ids,
                "externalIds": external_ids,
                "formattedAddress": formatted_address,
                "geofence": convert_and_respect_annotation_metadata(
                    object_=geofence, annotation=CreateAddressRequestGeofence, direction="write"
                ),
                "latitude": latitude,
                "longitude": longitude,
                "name": name,
                "notes": notes,
                "tagIds": tag_ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddressResponse,
                    parse_obj_as(
                        type_=AddressResponse,  # 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(
        self, id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[AddressResponse]:
        """
        Returns a specific address.

         **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 Addresses** under the Addresses 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 Address. 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`

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

        Returns
        -------
        AsyncHttpResponse[AddressResponse]
            An Address.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"addresses/{jsonable_encoder(id)}",
            method="GET",
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddressResponse,
                    parse_obj_as(
                        type_=AddressResponse,  # 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]:
        """
        Delete a specific address.

         **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 Addresses** under the Addresses 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 Address. 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`

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

        Returns
        -------
        AsyncHttpResponse[None]
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"addresses/{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 update(
        self,
        id: str,
        *,
        address_types: typing.Optional[typing.Sequence[UpdateAddressRequestAddressTypesItem]] = OMIT,
        contact_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        external_ids: typing.Optional[typing.Dict[str, str]] = OMIT,
        formatted_address: typing.Optional[str] = OMIT,
        geofence: typing.Optional[UpdateAddressRequestGeofence] = OMIT,
        latitude: typing.Optional[float] = OMIT,
        longitude: typing.Optional[float] = OMIT,
        name: typing.Optional[str] = OMIT,
        notes: typing.Optional[str] = OMIT,
        tag_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AddressResponse]:
        """
        Update a specific address.

         **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 Addresses** under the Addresses 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 Address. 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`

        address_types : typing.Optional[typing.Sequence[UpdateAddressRequestAddressTypesItem]]
            Reporting location type associated with the address (used for ELD reporting purposes). Valid values: `yard`, `shortHaul`, `workforceSite`, `riskZone`, `industrialSite`, `alertsOnly`, `agricultureSource`, `avoidanceZone`, `knownGPSJammingZone`, `authorizedZone`, `unauthorizedZone`, `vendor`, `inventory`.

        contact_ids : typing.Optional[typing.Sequence[str]]
            An array of Contact IDs associated with this Address.

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

        formatted_address : typing.Optional[str]
            The full street address for this address/geofence, as it might be recognized by Google Maps.

        geofence : typing.Optional[UpdateAddressRequestGeofence]

        latitude : typing.Optional[float]
            Latitude of the address. Will be geocoded from `formattedAddress` if not provided.

        longitude : typing.Optional[float]
            Longitude of the address. Will be geocoded from `formattedAddress` if not provided.

        name : typing.Optional[str]
            Name of the address.

        notes : typing.Optional[str]
            Notes about the address.

        tag_ids : typing.Optional[typing.Sequence[str]]
            An array of IDs of tags to associate with this address.

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

        Returns
        -------
        AsyncHttpResponse[AddressResponse]
            Updated address object with ID.
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"addresses/{jsonable_encoder(id)}",
            method="PATCH",
            json={
                "addressTypes": address_types,
                "contactIds": contact_ids,
                "externalIds": external_ids,
                "formattedAddress": formatted_address,
                "geofence": convert_and_respect_annotation_metadata(
                    object_=geofence, annotation=UpdateAddressRequestGeofence, direction="write"
                ),
                "latitude": latitude,
                "longitude": longitude,
                "name": name,
                "notes": notes,
                "tagIds": tag_ids,
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AddressResponse,
                    parse_obj_as(
                        type_=AddressResponse,  # 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)
