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.bag_item_dto_format import BagItemDtoFormat
from ..models.bag_item_dto_product import BagItemDtoProduct
from ..models.bag_item_dto_product_type import BagItemDtoProductType
from ..models.bag_item_dto_service_level import BagItemDtoServiceLevel
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.bag_item_content_dto import BagItemContentDto
    from ..models.country import Country


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


@_attrs_define
class BagItemDto:
    """
    Attributes:
        id (int | Unset):
        barcode (str | Unset):
        customer_ekp (str | Unset):
        awb (str | Unset):
        destination_country (Country | Unset):
        destination_email (str | Unset):
        destination_phone (str | Unset):
        destination_phone_2 (str | Unset):
        format_ (BagItemDtoFormat | Unset):
        item_weight (int | Unset):
        bag_id (str | Unset): In requests only applicable for customers using "prelabelled service"
        product_type (BagItemDtoProductType | Unset):
        product (BagItemDtoProduct | Unset):
        service_level (BagItemDtoServiceLevel | Unset):
        name (str | Unset):
        customer_reference (str | Unset):
        recipient_phone (str | Unset):
        recipient_email (str | Unset):
        address_line_1 (str | Unset):
        address_line_2 (str | Unset):
        address_line_3 (str | Unset):
        city (str | Unset):
        destination_state (str | Unset):
        postal_code (str | Unset):
        currency (str | Unset):
        content_type (str | Unset):
        declared_content_amount (int | Unset):
        detailed_content_descriptions_1 (str | Unset):
        total_value (int | Unset):
        return_label (bool | Unset):
        sender_customs_reference (str | Unset):
        importer_customs_reference (str | Unset):
        checked (bool | Unset):
        bag_item_contents (list[BagItemContentDto] | Unset):
    """

    id: int | Unset = UNSET
    barcode: str | Unset = UNSET
    customer_ekp: str | Unset = UNSET
    awb: str | Unset = UNSET
    destination_country: Country | Unset = UNSET
    destination_email: str | Unset = UNSET
    destination_phone: str | Unset = UNSET
    destination_phone_2: str | Unset = UNSET
    format_: BagItemDtoFormat | Unset = UNSET
    item_weight: int | Unset = UNSET
    bag_id: str | Unset = UNSET
    product_type: BagItemDtoProductType | Unset = UNSET
    product: BagItemDtoProduct | Unset = UNSET
    service_level: BagItemDtoServiceLevel | Unset = UNSET
    name: str | Unset = UNSET
    customer_reference: str | Unset = UNSET
    recipient_phone: str | Unset = UNSET
    recipient_email: str | Unset = UNSET
    address_line_1: str | Unset = UNSET
    address_line_2: str | Unset = UNSET
    address_line_3: str | Unset = UNSET
    city: str | Unset = UNSET
    destination_state: str | Unset = UNSET
    postal_code: str | Unset = UNSET
    currency: str | Unset = UNSET
    content_type: str | Unset = UNSET
    declared_content_amount: int | Unset = UNSET
    detailed_content_descriptions_1: str | Unset = UNSET
    total_value: int | Unset = UNSET
    return_label: bool | Unset = UNSET
    sender_customs_reference: str | Unset = UNSET
    importer_customs_reference: str | Unset = UNSET
    checked: bool | Unset = UNSET
    bag_item_contents: list[BagItemContentDto] | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        barcode = self.barcode

        customer_ekp = self.customer_ekp

        awb = self.awb

        destination_country: dict[str, Any] | Unset = UNSET
        if not isinstance(self.destination_country, Unset):
            destination_country = self.destination_country.to_dict()

        destination_email = self.destination_email

        destination_phone = self.destination_phone

        destination_phone_2 = self.destination_phone_2

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

        item_weight = self.item_weight

        bag_id = self.bag_id

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

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

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

        name = self.name

        customer_reference = self.customer_reference

        recipient_phone = self.recipient_phone

        recipient_email = self.recipient_email

        address_line_1 = self.address_line_1

        address_line_2 = self.address_line_2

        address_line_3 = self.address_line_3

        city = self.city

        destination_state = self.destination_state

        postal_code = self.postal_code

        currency = self.currency

        content_type = self.content_type

        declared_content_amount = self.declared_content_amount

        detailed_content_descriptions_1 = self.detailed_content_descriptions_1

        total_value = self.total_value

        return_label = self.return_label

        sender_customs_reference = self.sender_customs_reference

        importer_customs_reference = self.importer_customs_reference

        checked = self.checked

        bag_item_contents: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.bag_item_contents, Unset):
            bag_item_contents = []
            for bag_item_contents_item_data in self.bag_item_contents:
                bag_item_contents_item = bag_item_contents_item_data.to_dict()
                bag_item_contents.append(bag_item_contents_item)

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if id is not UNSET:
            field_dict["id"] = id
        if barcode is not UNSET:
            field_dict["barcode"] = barcode
        if customer_ekp is not UNSET:
            field_dict["customerEkp"] = customer_ekp
        if awb is not UNSET:
            field_dict["awb"] = awb
        if destination_country is not UNSET:
            field_dict["destinationCountry"] = destination_country
        if destination_email is not UNSET:
            field_dict["destinationEmail"] = destination_email
        if destination_phone is not UNSET:
            field_dict["destinationPhone"] = destination_phone
        if destination_phone_2 is not UNSET:
            field_dict["destinationPhone2"] = destination_phone_2
        if format_ is not UNSET:
            field_dict["format"] = format_
        if item_weight is not UNSET:
            field_dict["itemWeight"] = item_weight
        if bag_id is not UNSET:
            field_dict["bagId"] = bag_id
        if product_type is not UNSET:
            field_dict["productType"] = product_type
        if product is not UNSET:
            field_dict["product"] = product
        if service_level is not UNSET:
            field_dict["serviceLevel"] = service_level
        if name is not UNSET:
            field_dict["name"] = name
        if customer_reference is not UNSET:
            field_dict["customerReference"] = customer_reference
        if recipient_phone is not UNSET:
            field_dict["recipientPhone"] = recipient_phone
        if recipient_email is not UNSET:
            field_dict["recipientEmail"] = recipient_email
        if address_line_1 is not UNSET:
            field_dict["addressLine1"] = address_line_1
        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 city is not UNSET:
            field_dict["city"] = city
        if destination_state is not UNSET:
            field_dict["destinationState"] = destination_state
        if postal_code is not UNSET:
            field_dict["postalCode"] = postal_code
        if currency is not UNSET:
            field_dict["currency"] = currency
        if content_type is not UNSET:
            field_dict["contentType"] = content_type
        if declared_content_amount is not UNSET:
            field_dict["declaredContentAmount"] = declared_content_amount
        if detailed_content_descriptions_1 is not UNSET:
            field_dict["detailedContentDescriptions1"] = detailed_content_descriptions_1
        if total_value is not UNSET:
            field_dict["totalValue"] = total_value
        if return_label is not UNSET:
            field_dict["returnLabel"] = return_label
        if sender_customs_reference is not UNSET:
            field_dict["senderCustomsReference"] = sender_customs_reference
        if importer_customs_reference is not UNSET:
            field_dict["importerCustomsReference"] = importer_customs_reference
        if checked is not UNSET:
            field_dict["checked"] = checked
        if bag_item_contents is not UNSET:
            field_dict["bagItemContents"] = bag_item_contents

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.bag_item_content_dto import BagItemContentDto
        from ..models.country import Country

        d = dict(src_dict)
        id = d.pop("id", UNSET)

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

        customer_ekp = d.pop("customerEkp", UNSET)

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

        _destination_country = d.pop("destinationCountry", UNSET)
        destination_country: Country | Unset
        if isinstance(_destination_country, Unset):
            destination_country = UNSET
        else:
            destination_country = Country.from_dict(_destination_country)

        destination_email = d.pop("destinationEmail", UNSET)

        destination_phone = d.pop("destinationPhone", UNSET)

        destination_phone_2 = d.pop("destinationPhone2", UNSET)

        _format_ = d.pop("format", UNSET)
        format_: BagItemDtoFormat | Unset
        if isinstance(_format_, Unset):
            format_ = UNSET
        else:
            format_ = BagItemDtoFormat(_format_)

        item_weight = d.pop("itemWeight", UNSET)

        bag_id = d.pop("bagId", UNSET)

        _product_type = d.pop("productType", UNSET)
        product_type: BagItemDtoProductType | Unset
        if isinstance(_product_type, Unset):
            product_type = UNSET
        else:
            product_type = BagItemDtoProductType(_product_type)

        _product = d.pop("product", UNSET)
        product: BagItemDtoProduct | Unset
        if isinstance(_product, Unset):
            product = UNSET
        else:
            product = BagItemDtoProduct(_product)

        _service_level = d.pop("serviceLevel", UNSET)
        service_level: BagItemDtoServiceLevel | Unset
        if isinstance(_service_level, Unset):
            service_level = UNSET
        else:
            service_level = BagItemDtoServiceLevel(_service_level)

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

        customer_reference = d.pop("customerReference", UNSET)

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

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

        address_line_1 = d.pop("addressLine1", UNSET)

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

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

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

        destination_state = d.pop("destinationState", UNSET)

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

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

        content_type = d.pop("contentType", UNSET)

        declared_content_amount = d.pop("declaredContentAmount", UNSET)

        detailed_content_descriptions_1 = d.pop("detailedContentDescriptions1", UNSET)

        total_value = d.pop("totalValue", UNSET)

        return_label = d.pop("returnLabel", UNSET)

        sender_customs_reference = d.pop("senderCustomsReference", UNSET)

        importer_customs_reference = d.pop("importerCustomsReference", UNSET)

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

        _bag_item_contents = d.pop("bagItemContents", UNSET)
        bag_item_contents: list[BagItemContentDto] | Unset = UNSET
        if _bag_item_contents is not UNSET:
            bag_item_contents = []
            for bag_item_contents_item_data in _bag_item_contents:
                bag_item_contents_item = BagItemContentDto.from_dict(bag_item_contents_item_data)

                bag_item_contents.append(bag_item_contents_item)

        bag_item_dto = cls(
            id=id,
            barcode=barcode,
            customer_ekp=customer_ekp,
            awb=awb,
            destination_country=destination_country,
            destination_email=destination_email,
            destination_phone=destination_phone,
            destination_phone_2=destination_phone_2,
            format_=format_,
            item_weight=item_weight,
            bag_id=bag_id,
            product_type=product_type,
            product=product,
            service_level=service_level,
            name=name,
            customer_reference=customer_reference,
            recipient_phone=recipient_phone,
            recipient_email=recipient_email,
            address_line_1=address_line_1,
            address_line_2=address_line_2,
            address_line_3=address_line_3,
            city=city,
            destination_state=destination_state,
            postal_code=postal_code,
            currency=currency,
            content_type=content_type,
            declared_content_amount=declared_content_amount,
            detailed_content_descriptions_1=detailed_content_descriptions_1,
            total_value=total_value,
            return_label=return_label,
            sender_customs_reference=sender_customs_reference,
            importer_customs_reference=importer_customs_reference,
            checked=checked,
            bag_item_contents=bag_item_contents,
        )

        bag_item_dto.additional_properties = d
        return bag_item_dto

    @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
