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

import json
from typing import Union, Annotated

from pydantic import Field

from tracking.models import (
    NotificationRequestV1,
    Notification,
)
from tracking.request import ApiClient, validate_params


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

    @validate_params
    def add_notification_by_slug_tracking_number(
        self,
        slug: Annotated[str, Field(min_length=1)],
        tracking_number: Annotated[str, Field(min_length=1)],
        add_notification_by_slug_tracking_number_request: Union[NotificationRequestV1, dict],
        **kwargs,
    ) -> Notification:
        """
        Add notification receivers to a tracking number.
        :param slug: str. Tracking slug.
        :param tracking_number: str. Tracking number.
        :param add_notification_by_slug_tracking_number_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).
            query params:
                **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/notifications/{slug}/{tracking_number}/add"
        params_keys = {
            "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}

        body = add_notification_by_slug_tracking_number_request
        if not isinstance(body, dict):
            body = add_notification_by_slug_tracking_number_request.model_dump(exclude_none=True)
        body = json.dumps({"notification": body})

        result = self._request("POST", url=url, params=params, body=body, **kwargs)
        return Notification().from_dict(result.get("notification"))

    @validate_params
    def add_notification_by_tracking_id(
        self,
        tracking_id: Annotated[str, Field(min_length=1)],
        add_notification_by_tracking_id_request: Union[NotificationRequestV1, dict],
        **kwargs,
    ) -> Notification:
        """
        Add notification receivers to a tracking number.
        :param tracking_id: str. tracking id.
        :param add_notification_by_tracking_id_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 = f"/tracking/2024-04/notifications/{tracking_id}/add"

        body = add_notification_by_tracking_id_request
        if not isinstance(body, dict):
            body = add_notification_by_tracking_id_request.model_dump(exclude_none=True)
        body = json.dumps({"notification": body})

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

    @validate_params
    def delete_notification_by_slug_tracking_number(
        self,
        slug: Annotated[str, Field(min_length=1)],
        tracking_number: Annotated[str, Field(min_length=1)],
        delete_notification_by_slug_tracking_number_request: Union[NotificationRequestV1, dict],
        **kwargs,
    ) -> Notification:
        """
        Remove notification receivers from a tracking number.
        :param slug: str. Tracking slug.
        :param tracking_number: str. Tracking number.
        :param delete_notification_by_slug_tracking_number_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).
            query params:
                **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/notifications/{slug}/{tracking_number}/remove"
        params_keys = {
            "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}

        body = delete_notification_by_slug_tracking_number_request
        if not isinstance(body, dict):
            body = delete_notification_by_slug_tracking_number_request.model_dump(exclude_none=True)
        body = json.dumps({"notification": body})

        result = self._request("POST", url=url, params=params, body=body, **kwargs)
        return Notification().from_dict(result.get("notification"))

    @validate_params
    def delete_notification_by_tracking_id(
        self,
        tracking_id: Annotated[str, Field(min_length=1)],
        delete_notification_by_tracking_id_request: Union[NotificationRequestV1, dict],
        **kwargs,
    ) -> Notification:
        """
        Remove notification receivers from a tracking number.
        :param tracking_id: str. tracking id.
        :param delete_notification_by_tracking_id_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 = f"/tracking/2024-04/notifications/{tracking_id}/remove"

        body = delete_notification_by_tracking_id_request
        if not isinstance(body, dict):
            body = delete_notification_by_tracking_id_request.model_dump(exclude_none=True)
        body = json.dumps({"notification": body})

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

    @validate_params
    def get_notification_by_slug_tracking_number(
        self,
        slug: Annotated[str, Field(min_length=1)],
        tracking_number: Annotated[str, Field(min_length=1)],
        **kwargs,
    ) -> Notification:
        """
        Get contact information for the users to notify when the tracking changes. Please note that only customer receivers will be returned. Any `email`, `sms` or `webhook` that belongs to the Store will not be returned.
        :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:
                **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/notifications/{slug}/{tracking_number}"
        params_keys = {
            "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 Notification().from_dict(result.get("notification"))

    @validate_params
    def get_notification_by_tracking_id(
        self, tracking_id: Annotated[str, Field(min_length=1)], **kwargs
    ) -> Notification:
        """
        Get contact information for the users to notify when the tracking changes. Please note that only customer receivers will be returned. Any `email`, `sms` or `webhook` that belongs to the Store will not be returned.
        :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).
        """
        url = f"/tracking/2024-04/notifications/{tracking_id}"

        result = self._request("GET", url=url, **kwargs)
        return Notification().from_dict(result.get("notification"))
