from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..models.awb_item_format import AwbItemFormat
from ..models.awb_product import AwbProduct
from ..models.awb_service_level import AwbServiceLevel
from ..types import UNSET, Unset

T = TypeVar("T", bound="Awb")


@_attrs_define
class Awb:
    """
    Example:
        {'customerEkp': '9012345678', 'contactName': 'Max Mustermann', 'awbCopyCount': 3, 'product': 'GMP',
            'serviceLevel': 'PRIORITY', 'itemFormat': 'P', 'jobReference': 'Job ref', 'totalWeight': 5, 'telephoneNumber':
            '+4935120681234'}

    Attributes:
        awb_copy_count (int): Copies of AWB labels. One AWB per final receptacle required. Number between 1 and 99.
            Example: 3.
        contact_name (str): Contact name for paperwork. Example: John Doe.
        customer_ekp (str): Deutsche Post Customer Account number (EKP) of the customer who wants to create an single
            awb. Example: 9012345678.
        item_format (AwbItemFormat): The item format for this awb. Example: P.
        product (AwbProduct): The product that is used for the shipment of this item. Available products are: GMP
            [Packet Priority/Prio (goods)], GPT [Packet Tracked/Tracked], GMM [Business Mail Priority/Prio (documents)], GMR
            [Business Mail Registered/Plus (documents)] Example: GMP.
        service_level (AwbServiceLevel): The service level that is used for the shipment of this item. There are
            restrictions for use of service level: Registered is only available with product GMR and SalesChannel DPI
            Example: PRIORITY.
        job_reference (str | Unset): Job reference for the whole shipment. Example: Internal ID 3/14.
        telephone_number (str | Unset): Telephone number for paperwork. Mandatory for sales channel EXPRESS. Example:
            +491234567890.
        total_weight (float | Unset): Total weight of the awb (in kg). Example: 5.
    """

    awb_copy_count: int
    contact_name: str
    customer_ekp: str
    item_format: AwbItemFormat
    product: AwbProduct
    service_level: AwbServiceLevel
    job_reference: str | Unset = UNSET
    telephone_number: str | Unset = UNSET
    total_weight: float | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        awb_copy_count = self.awb_copy_count

        contact_name = self.contact_name

        customer_ekp = self.customer_ekp

        item_format = self.item_format.value

        product = self.product.value

        service_level = self.service_level.value

        job_reference = self.job_reference

        telephone_number = self.telephone_number

        total_weight = self.total_weight

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "awbCopyCount": awb_copy_count,
                "contactName": contact_name,
                "customerEkp": customer_ekp,
                "itemFormat": item_format,
                "product": product,
                "serviceLevel": service_level,
            }
        )
        if job_reference is not UNSET:
            field_dict["jobReference"] = job_reference
        if telephone_number is not UNSET:
            field_dict["telephoneNumber"] = telephone_number
        if total_weight is not UNSET:
            field_dict["totalWeight"] = total_weight

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        d = dict(src_dict)
        awb_copy_count = d.pop("awbCopyCount")

        contact_name = d.pop("contactName")

        customer_ekp = d.pop("customerEkp")

        item_format = AwbItemFormat(d.pop("itemFormat"))

        product = AwbProduct(d.pop("product"))

        service_level = AwbServiceLevel(d.pop("serviceLevel"))

        job_reference = d.pop("jobReference", UNSET)

        telephone_number = d.pop("telephoneNumber", UNSET)

        total_weight = d.pop("totalWeight", UNSET)

        awb = cls(
            awb_copy_count=awb_copy_count,
            contact_name=contact_name,
            customer_ekp=customer_ekp,
            item_format=item_format,
            product=product,
            service_level=service_level,
            job_reference=job_reference,
            telephone_number=telephone_number,
            total_weight=total_weight,
        )

        awb.additional_properties = d
        return awb

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties
