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

import json
from typing import Union


from tracking.models import (
    DetectCourierRequest,
    DetectCourierResponse,
    GetCouriersResponse,
)
from tracking.request import ApiClient, validate_params


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

    @validate_params
    def detect_courier(
        self, detect_courier_request: Union[DetectCourierRequest, dict], **kwargs
    ) -> DetectCourierResponse:
        """
        Return a list of matched couriers based on tracking number format and  or a list of couriers.
        :param detect_courier_request:
        :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).
        """
        url = "/tracking/2025-07/couriers/detect"

        body = detect_courier_request
        if not isinstance(body, dict):
            body = detect_courier_request.model_dump(exclude_none=True)
        body = json.dumps(body)

        result = self._request("POST", url=url, body=body, **kwargs)
        return DetectCourierResponse().from_dict(result)

    @validate_params
    def get_couriers(self, **kwargs) -> GetCouriersResponse:
        """
        Return a list of couriers.
        :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:
                **active**: bool. get user activated couriers
                **slug**: str. Unique courier code Use comma for multiple values. (Example: dhl,ups,usps)
        """
        url = "/tracking/2025-07/couriers"
        params_keys = {
            "active",
            "slug",
        }
        params = {key: kwargs.pop(key) for key in params_keys if key in kwargs}

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