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 ..types import UNSET, Unset

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


@_attrs_define
class Content:
    """
    Example:
        {'contentPieceHsCode': 1234567890, 'contentPieceDescription': 'Trousers', 'contentPieceValue': '120.50',
            'contentPieceNetweight': 1200, 'contentPieceOrigin': 'DE', 'contentPieceAmount': 2}

    Attributes:
        content_piece_amount (int): Number of pieces. Example: 2.
        content_piece_description (str): The (short) description of this content. Example: Trousers.
        content_piece_netweight (int): The net weight of all pieces of this content type. Example: 1200.
        content_piece_origin (str): Country of origin, based on ISO-3166-1. Example: DE.
        content_piece_value (str): Overall value of the content pieces of one type. 1 to 4 digits before the decimal
            point, 2 digits after the decimal point or 1 to 7 digits without decimal point Example: 120.50.
        content_piece_hs_code (str | Unset): The HS code of this content. Only 6, 8 or 10 digits, with at most one
            leading zero.
            HS Code mandatory for all shipments requiring a CN22 customs declaration. Example: 1234567890.
        content_piece_index_number (int | Unset): NOT RECOMMENDED, obsolete and should not be contained in requests
            until further notice.
    """

    content_piece_amount: int
    content_piece_description: str
    content_piece_netweight: int
    content_piece_origin: str
    content_piece_value: str
    content_piece_hs_code: str | Unset = UNSET
    content_piece_index_number: int | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        content_piece_description = self.content_piece_description

        content_piece_netweight = self.content_piece_netweight

        content_piece_origin = self.content_piece_origin

        content_piece_value = self.content_piece_value

        content_piece_hs_code = self.content_piece_hs_code

        content_piece_index_number = self.content_piece_index_number

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "contentPieceAmount": content_piece_amount,
                "contentPieceDescription": content_piece_description,
                "contentPieceNetweight": content_piece_netweight,
                "contentPieceOrigin": content_piece_origin,
                "contentPieceValue": content_piece_value,
            }
        )
        if content_piece_hs_code is not UNSET:
            field_dict["contentPieceHsCode"] = content_piece_hs_code
        if content_piece_index_number is not UNSET:
            field_dict["contentPieceIndexNumber"] = content_piece_index_number

        return field_dict

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

        content_piece_description = d.pop("contentPieceDescription")

        content_piece_netweight = d.pop("contentPieceNetweight")

        content_piece_origin = d.pop("contentPieceOrigin")

        content_piece_value = d.pop("contentPieceValue")

        content_piece_hs_code = d.pop("contentPieceHsCode", UNSET)

        content_piece_index_number = d.pop("contentPieceIndexNumber", UNSET)

        content = cls(
            content_piece_amount=content_piece_amount,
            content_piece_description=content_piece_description,
            content_piece_netweight=content_piece_netweight,
            content_piece_origin=content_piece_origin,
            content_piece_value=content_piece_value,
            content_piece_hs_code=content_piece_hs_code,
            content_piece_index_number=content_piece_index_number,
        )

        content.additional_properties = d
        return content

    @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
