from __future__ import annotations

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

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

from ..models.item_data_service_level import ItemDataServiceLevel
from ..models.item_data_shipment_naturetype import ItemDataShipmentNaturetype
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.content import Content


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


@_attrs_define
class ItemData:
    """
    Example:
        {'id': 1, 'product': 'GMP', 'serviceLevel': 'PRIORITY', 'custRef': 'REF-2361890-AB', 'recipient': 'John Doe',
            'recipientPhone': '+4935120681234', 'recipientFax': '+4935120681234', 'recipientEmail': 'john.doe@example.eu',
            'addressLine1': 'Mustergasse 12', 'addressLine2': 'Hinterhaus', 'addressLine3': '1. Etage', 'city': 'Dresden',
            'state': 'Sachsen', 'postalCode': '01432', 'destinationCountry': 'DE', 'shipmentAmount': 100,
            'shipmentCurrency': 'EUR', 'shipmentGrossWeight': 1500, 'returnItemWanted': False, 'shipmentNaturetype':
            'SALE_GOODS', 'contents': [{'contentPieceHsCode': 1234567890, 'contentPieceDescription': 'Trousers',
            'contentPieceValue': '120.50', 'contentPieceNetweight': 1200, 'contentPieceOrigin': 'DE', 'contentPieceAmount':
            2}]}

    Attributes:
        address_line_1 (str): First line of address information of the recipient.
            No unicode replacement characters � or question mark is accepted. Example: Any Street 100.
        city (str): City of the recipient address.
            No unicode replacement characters � or question mark is accepted. Example: Any City.
        destination_country (str): Destination country of the item, based on ISO-3166-1. Please check
            https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2 for further details. Example: DE.
        product (str): 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.
        recipient (str): Name of the recipient.
            No unicode replacement characters � and max. one question mark is accepted. Example: John Doe.
        service_level (ItemDataServiceLevel): 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.
        shipment_gross_weight (int): Gross weight of the item (in g). May not exceed 2000 g. Example: 1500.
        address_line_2 (str | Unset): Second line of address information of the recipient.
            No unicode replacement characters � or question mark is accepted. Example: Flat 2.
        address_line_3 (str | Unset): Third line of address information of the recipient.
            No unicode replacement characters � or question mark is accepted. Example: 1st floor.
        contents (list[Content] | Unset): The descriptions of the content pieces.
        cust_ref (str | Unset): Reference text up to customer's choice Example: REF-2361890-AB.
        cust_ref_2 (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        cust_ref_3 (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        postal_code (str | Unset): Postal code of the recipient address. Consists of
            numbers, upper case letters, and one space or dash between characters
            No unicode replacement characters � or question mark is accepted. Example: 794.
        importer_tax_id (str | Unset): Customs reference number of the recipient, if required and applicable e.g. EORI
            number. Example: EORI: LU12345.
        recipient_email (str | Unset): Email address of the recipient. Used for notification.
            recipientEmail OR recipientPhone required for interconnect countries!

            An e-mail address or phone number for the recipient must be provided. Many postal operators have implemented
            electronic pick-up notifications by e-mail or SMS and the provision of this information is essential to ensure
            the smooth delivery of your shipments. Example: john.doe@example.eu.
        recipient_fax (str | Unset): Fax number of the recipient Example: +441234567891.
        recipient_phone (str | Unset): Phone number of the recipient
            recipientEmail OR recipientPhone required for interconnect countries!

            An e-mail address or phone number for the recipient must be provided. Many postal operators have implemented
            electronic pick-up notifications by e-mail or SMS and the provision of this information is essential to ensure
            the smooth delivery of your shipments. Example: +441234567891.
        return_item_wanted (bool | Unset): States if a return label should be created additionally. Requires a contract
            for Packet Return. Default: False.
        sender_address_line_1 (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until
            further notice.
        sender_address_line_2 (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until
            further notice.
        sender_city (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        sender_country (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        sender_email (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        sender_name (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        sender_phone (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until further
            notice.
        sender_postal_code (str | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests until
            further notice.
        sender_tax_id (str | Unset): Customs reference number of the sender, if applicable e.g. IOSS or VOEC number.
            Example: IOSS: ABC12345.
        shipment_amount (float | Unset): Overall value of all content pieces of the item. Example: 100.
        shipment_currency (str | Unset): Currency code of the value, based on ISO-4217. Please check
            https://en.wikipedia.org/wiki/ISO_4217#Active_codes for further details. Example: EUR.
        shipment_naturetype (ItemDataShipmentNaturetype | Unset): Nature of the pieces in this item. Mandatory for non-
            EU shipments: SALE_GOODS, RETURN_GOODS, COMMERCIAL_SAMPLE, DOCUMENTS, MIXED_CONTENTS, OTHERS. Mandatory for non-
            EU shipments. Example: SALE_GOODS.
        state (str | Unset): State of the recipient address.
            No unicode replacement characters � or question mark is accepted.
            An empty string is still allowed Example: NC.
    """

    address_line_1: str
    city: str
    destination_country: str
    product: str
    recipient: str
    service_level: ItemDataServiceLevel
    shipment_gross_weight: int
    address_line_2: str | Unset = UNSET
    address_line_3: str | Unset = UNSET
    contents: list[Content] | Unset = UNSET
    cust_ref: str | Unset = UNSET
    cust_ref_2: str | Unset = UNSET
    cust_ref_3: str | Unset = UNSET
    postal_code: str | Unset = UNSET
    importer_tax_id: str | Unset = UNSET
    recipient_email: str | Unset = UNSET
    recipient_fax: str | Unset = UNSET
    recipient_phone: str | Unset = UNSET
    return_item_wanted: bool | Unset = False
    sender_address_line_1: str | Unset = UNSET
    sender_address_line_2: str | Unset = UNSET
    sender_city: str | Unset = UNSET
    sender_country: str | Unset = UNSET
    sender_email: str | Unset = UNSET
    sender_name: str | Unset = UNSET
    sender_phone: str | Unset = UNSET
    sender_postal_code: str | Unset = UNSET
    sender_tax_id: str | Unset = UNSET
    shipment_amount: float | Unset = UNSET
    shipment_currency: str | Unset = UNSET
    shipment_naturetype: ItemDataShipmentNaturetype | Unset = UNSET
    state: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        city = self.city

        destination_country = self.destination_country

        product = self.product

        recipient = self.recipient

        service_level = self.service_level.value

        shipment_gross_weight = self.shipment_gross_weight

        address_line_2 = self.address_line_2

        address_line_3 = self.address_line_3

        contents: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.contents, Unset):
            contents = []
            for contents_item_data in self.contents:
                contents_item = contents_item_data.to_dict()
                contents.append(contents_item)

        cust_ref = self.cust_ref

        cust_ref_2 = self.cust_ref_2

        cust_ref_3 = self.cust_ref_3

        postal_code = self.postal_code

        importer_tax_id = self.importer_tax_id

        recipient_email = self.recipient_email

        recipient_fax = self.recipient_fax

        recipient_phone = self.recipient_phone

        return_item_wanted = self.return_item_wanted

        sender_address_line_1 = self.sender_address_line_1

        sender_address_line_2 = self.sender_address_line_2

        sender_city = self.sender_city

        sender_country = self.sender_country

        sender_email = self.sender_email

        sender_name = self.sender_name

        sender_phone = self.sender_phone

        sender_postal_code = self.sender_postal_code

        sender_tax_id = self.sender_tax_id

        shipment_amount = self.shipment_amount

        shipment_currency = self.shipment_currency

        shipment_naturetype: str | Unset = UNSET
        if not isinstance(self.shipment_naturetype, Unset):
            shipment_naturetype = self.shipment_naturetype.value

        state = self.state

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "addressLine1": address_line_1,
                "city": city,
                "destinationCountry": destination_country,
                "product": product,
                "recipient": recipient,
                "serviceLevel": service_level,
                "shipmentGrossWeight": shipment_gross_weight,
            }
        )
        if address_line_2 is not UNSET:
            field_dict["addressLine2"] = address_line_2
        if address_line_3 is not UNSET:
            field_dict["addressLine3"] = address_line_3
        if contents is not UNSET:
            field_dict["contents"] = contents
        if cust_ref is not UNSET:
            field_dict["custRef"] = cust_ref
        if cust_ref_2 is not UNSET:
            field_dict["custRef2"] = cust_ref_2
        if cust_ref_3 is not UNSET:
            field_dict["custRef3"] = cust_ref_3
        if postal_code is not UNSET:
            field_dict["postalCode"] = postal_code
        if importer_tax_id is not UNSET:
            field_dict["importerTaxId"] = importer_tax_id
        if recipient_email is not UNSET:
            field_dict["recipientEmail"] = recipient_email
        if recipient_fax is not UNSET:
            field_dict["recipientFax"] = recipient_fax
        if recipient_phone is not UNSET:
            field_dict["recipientPhone"] = recipient_phone
        if return_item_wanted is not UNSET:
            field_dict["returnItemWanted"] = return_item_wanted
        if sender_address_line_1 is not UNSET:
            field_dict["senderAddressLine1"] = sender_address_line_1
        if sender_address_line_2 is not UNSET:
            field_dict["senderAddressLine2"] = sender_address_line_2
        if sender_city is not UNSET:
            field_dict["senderCity"] = sender_city
        if sender_country is not UNSET:
            field_dict["senderCountry"] = sender_country
        if sender_email is not UNSET:
            field_dict["senderEmail"] = sender_email
        if sender_name is not UNSET:
            field_dict["senderName"] = sender_name
        if sender_phone is not UNSET:
            field_dict["senderPhone"] = sender_phone
        if sender_postal_code is not UNSET:
            field_dict["senderPostalCode"] = sender_postal_code
        if sender_tax_id is not UNSET:
            field_dict["senderTaxId"] = sender_tax_id
        if shipment_amount is not UNSET:
            field_dict["shipmentAmount"] = shipment_amount
        if shipment_currency is not UNSET:
            field_dict["shipmentCurrency"] = shipment_currency
        if shipment_naturetype is not UNSET:
            field_dict["shipmentNaturetype"] = shipment_naturetype
        if state is not UNSET:
            field_dict["state"] = state

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.content import Content

        d = dict(src_dict)
        address_line_1 = d.pop("addressLine1")

        city = d.pop("city")

        destination_country = d.pop("destinationCountry")

        product = d.pop("product")

        recipient = d.pop("recipient")

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

        shipment_gross_weight = d.pop("shipmentGrossWeight")

        address_line_2 = d.pop("addressLine2", UNSET)

        address_line_3 = d.pop("addressLine3", UNSET)

        _contents = d.pop("contents", UNSET)
        contents: list[Content] | Unset = UNSET
        if _contents is not UNSET:
            contents = []
            for contents_item_data in _contents:
                contents_item = Content.from_dict(contents_item_data)

                contents.append(contents_item)

        cust_ref = d.pop("custRef", UNSET)

        cust_ref_2 = d.pop("custRef2", UNSET)

        cust_ref_3 = d.pop("custRef3", UNSET)

        postal_code = d.pop("postalCode", UNSET)

        importer_tax_id = d.pop("importerTaxId", UNSET)

        recipient_email = d.pop("recipientEmail", UNSET)

        recipient_fax = d.pop("recipientFax", UNSET)

        recipient_phone = d.pop("recipientPhone", UNSET)

        return_item_wanted = d.pop("returnItemWanted", UNSET)

        sender_address_line_1 = d.pop("senderAddressLine1", UNSET)

        sender_address_line_2 = d.pop("senderAddressLine2", UNSET)

        sender_city = d.pop("senderCity", UNSET)

        sender_country = d.pop("senderCountry", UNSET)

        sender_email = d.pop("senderEmail", UNSET)

        sender_name = d.pop("senderName", UNSET)

        sender_phone = d.pop("senderPhone", UNSET)

        sender_postal_code = d.pop("senderPostalCode", UNSET)

        sender_tax_id = d.pop("senderTaxId", UNSET)

        shipment_amount = d.pop("shipmentAmount", UNSET)

        shipment_currency = d.pop("shipmentCurrency", UNSET)

        _shipment_naturetype = d.pop("shipmentNaturetype", UNSET)
        shipment_naturetype: ItemDataShipmentNaturetype | Unset
        if isinstance(_shipment_naturetype, Unset):
            shipment_naturetype = UNSET
        else:
            shipment_naturetype = ItemDataShipmentNaturetype(_shipment_naturetype)

        state = d.pop("state", UNSET)

        item_data = cls(
            address_line_1=address_line_1,
            city=city,
            destination_country=destination_country,
            product=product,
            recipient=recipient,
            service_level=service_level,
            shipment_gross_weight=shipment_gross_weight,
            address_line_2=address_line_2,
            address_line_3=address_line_3,
            contents=contents,
            cust_ref=cust_ref,
            cust_ref_2=cust_ref_2,
            cust_ref_3=cust_ref_3,
            postal_code=postal_code,
            importer_tax_id=importer_tax_id,
            recipient_email=recipient_email,
            recipient_fax=recipient_fax,
            recipient_phone=recipient_phone,
            return_item_wanted=return_item_wanted,
            sender_address_line_1=sender_address_line_1,
            sender_address_line_2=sender_address_line_2,
            sender_city=sender_city,
            sender_country=sender_country,
            sender_email=sender_email,
            sender_name=sender_name,
            sender_phone=sender_phone,
            sender_postal_code=sender_postal_code,
            sender_tax_id=sender_tax_id,
            shipment_amount=shipment_amount,
            shipment_currency=shipment_currency,
            shipment_naturetype=shipment_naturetype,
            state=state,
        )

        item_data.additional_properties = d
        return item_data

    @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
