# coding: utf-8
#
# This code was auto generated by AfterShip SDK Generator.
# Do not edit the class manually.

from typing import Annotated

from pydantic import Field

from tracking.models import (
    GetCheckpointBySlugTrackingNumberResponse,
    GetCheckpointByTrackingIdResponse,
)
from tracking.request import ApiClient, validate_params


class LastCheckpointApi(ApiClient):
    """LastCheckpointApi api implements"""

    @validate_params
    def get_checkpoint_by_slug_tracking_number(
        self,
        slug: Annotated[str, Field(min_length=1)],
        tracking_number: Annotated[str, Field(min_length=1)],
        **kwargs,
    ) -> GetCheckpointBySlugTrackingNumberResponse:
        """
        Return the tracking information of the last checkpoint of a single tracking.
        :param slug: str. Tracking slug.
        :param tracking_number: str. Tracking number.
        :param kwargs:
            request options:
                **headers** (dict): support custom headers.
                **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to
                    verify the identity of requested hosts. Either `True` (default CA bundle),
                    a path to an SSL certificate file, an `ssl.SSLContext`, or `False`
                    (which will disable verification).
            query params:
                **fields**: str. List of fields to include in the response. Use comma for multiple values. Fields to include: `slug`, `created_at`, `checkpoint_time`, `city`, `coordinates`, `country_iso3`, `country_name`, `message`, `state`, `tag`, `zip`
                **lang**: str. Support Chinese to English translation for `china-ems` and `china-post` only
                **tracking_account_number**: str. Additional field required by some carriers to retrieve the tracking info. The shipper’s carrier account number. Refer to our article on  for more details.
                **tracking_origin_country**: str. Additional field required by some carriers to retrieve the tracking info. The origin country/region of the shipment. Refer to our article on  for more details.
                **tracking_destination_country**: str. Additional field required by some carriers to retrieve the tracking info. The destination country/region of the shipment. Refer to our article on  for more details.
                **tracking_key**: str. Additional field required by some carriers to retrieve the tracking info. A type of tracking credential required by some carriers. Refer to our article on  for more details.
                **tracking_postal_code**: str. Additional field required by some carriers to retrieve the tracking info. The postal code of the recipient’s address. Refer to our article on  for more details.
                **tracking_ship_date**: str. Additional field required by some carriers to retrieve the tracking info. The date the shipment was sent, using the format YYYYMMDD. Refer to our article on  for more details.
                **tracking_state**: str. Additional field required by some carriers to retrieve the tracking info. The state/province of the recipient’s address. Refer to our article on  for more details.
        """
        url = f"/tracking/2024-04/last_checkpoint/{slug}/{tracking_number}"
        params_keys = {
            "fields",
            "lang",
            "tracking_account_number",
            "tracking_origin_country",
            "tracking_destination_country",
            "tracking_key",
            "tracking_postal_code",
            "tracking_ship_date",
            "tracking_state",
        }
        params = {key: kwargs.pop(key) for key in params_keys if key in kwargs}

        result = self._request("GET", url=url, params=params, **kwargs)
        return GetCheckpointBySlugTrackingNumberResponse().from_dict(result)

    @validate_params
    def get_checkpoint_by_tracking_id(
        self, tracking_id: Annotated[str, Field(min_length=1)], **kwargs
    ) -> GetCheckpointByTrackingIdResponse:
        """
        Return the tracking information of the last checkpoint of a single tracking.
        :param tracking_id: str. tracking id.
        :param kwargs:
            request options:
                **headers** (dict): support custom headers.
                **verify** bool|str|SSLContext: SSL certificates (a.k.a CA bundle) used to
                    verify the identity of requested hosts. Either `True` (default CA bundle),
                    a path to an SSL certificate file, an `ssl.SSLContext`, or `False`
                    (which will disable verification).
            query params:
                **fields**: str. List of fields to include in the response. Use comma for multiple values. Fields to include: `slug`, `created_at`, `checkpoint_time`, `city`, `coordinates`, `country_iso3`, `country_name`, `message`, `state`, `tag`, `zip`
                **lang**: str. Support Chinese to English translation for `china-ems` and `china-post` only
        """
        url = f"/tracking/2024-04/last_checkpoint/{tracking_id}"
        params_keys = {
            "fields",
            "lang",
        }
        params = {key: kwargs.pop(key) for key in params_keys if key in kwargs}

        result = self._request("GET", url=url, params=params, **kwargs)
        return GetCheckpointByTrackingIdResponse().from_dict(result)
