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

if TYPE_CHECKING:
    from ..models.item_data import ItemData


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


@_attrs_define
class Validation:
    """
    Example:
        {'customerEkp': '9012345678', 'items': [{'product': 'GMP', 'serviceLevel': 'PRIORITY', 'custRef': '02 03 02 02
            T005', 'recipient': 'Herschel Krustofsky', 'recipientPhone': '', 'recipientFax': '', 'recipientEmail': '',
            'addressLine1': 'Avenue des Champs-Élysées', 'addressLine2': '', 'addressLine3': '103', 'city': 'Paris',
            'state': 'Île-de-France', 'postalCode': '75020', 'destinationCountry': 'FR', 'returnItemWanted': False,
            'shipmentAmount': 0, 'shipmentCurrency': 'EUR', 'shipmentGrossWeight': 500}]}

    Attributes:
        customer_ekp (str): Customer Ekp
        items (list[ItemData]): list of order Items
    """

    customer_ekp: str
    items: list[ItemData]
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        items = []
        for items_item_data in self.items:
            items_item = items_item_data.to_dict()
            items.append(items_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "customerEkp": customer_ekp,
                "items": items,
            }
        )

        return field_dict

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

        d = dict(src_dict)
        customer_ekp = d.pop("customerEkp")

        items = []
        _items = d.pop("items")
        for items_item_data in _items:
            items_item = ItemData.from_dict(items_item_data)

            items.append(items_item)

        validation = cls(
            customer_ekp=customer_ekp,
            items=items,
        )

        validation.additional_properties = d
        return validation

    @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
