from __future__ import annotations

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

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

from ..models.closed_bag_service_level import ClosedBagServiceLevel
from ..types import UNSET, Unset

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


@_attrs_define
class ClosedBag:
    """
    Attributes:
        product (str): The product that is used for the shipment of this item. Available products are: GMP (Packet), GMM
            (Business Mail Standard). Example: GMM.
        format_ (str): The format of the content of this bag.
        service_level (ClosedBagServiceLevel): The service level that is used for the shipment of this item. There are
            restrictions for use of service level: STANDARD is only available with products GMM and GMP, PRIORITY is only
            available with products GMM and GMP. Example: PRIORITY.
        destination_country (str): The destination country code.
        item_barcodes (list[str]): The barcodes of the already created items.
        bag_id (str | Unset): The BagId to track the bag. In requests only applicable for customers using "prelabelled
            service"
        item_count (int | Unset): The number of items. This value is only for the response.
        net_bulk_weight_in_kilogram (float | Unset): The weight of items. This value is only for the response.
        customer_ekp (str | Unset): The customer ekp. This value is only for the response.
    """

    product: str
    format_: str
    service_level: ClosedBagServiceLevel
    destination_country: str
    item_barcodes: list[str]
    bag_id: str | Unset = UNSET
    item_count: int | Unset = UNSET
    net_bulk_weight_in_kilogram: float | Unset = UNSET
    customer_ekp: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        format_ = self.format_

        service_level = self.service_level.value

        destination_country = self.destination_country

        item_barcodes = self.item_barcodes

        bag_id = self.bag_id

        item_count = self.item_count

        net_bulk_weight_in_kilogram = self.net_bulk_weight_in_kilogram

        customer_ekp = self.customer_ekp

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "product": product,
                "format": format_,
                "serviceLevel": service_level,
                "destinationCountry": destination_country,
                "itemBarcodes": item_barcodes,
            }
        )
        if bag_id is not UNSET:
            field_dict["bagId"] = bag_id
        if item_count is not UNSET:
            field_dict["itemCount"] = item_count
        if net_bulk_weight_in_kilogram is not UNSET:
            field_dict["netBulkWeightInKilogram"] = net_bulk_weight_in_kilogram
        if customer_ekp is not UNSET:
            field_dict["customerEkp"] = customer_ekp

        return field_dict

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

        format_ = d.pop("format")

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

        destination_country = d.pop("destinationCountry")

        item_barcodes = cast(list[str], d.pop("itemBarcodes"))

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

        item_count = d.pop("itemCount", UNSET)

        net_bulk_weight_in_kilogram = d.pop("netBulkWeightInKilogram", UNSET)

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

        closed_bag = cls(
            product=product,
            format_=format_,
            service_level=service_level,
            destination_country=destination_country,
            item_barcodes=item_barcodes,
            bag_id=bag_id,
            item_count=item_count,
            net_bulk_weight_in_kilogram=net_bulk_weight_in_kilogram,
            customer_ekp=customer_ekp,
        )

        closed_bag.additional_properties = d
        return closed_bag

    @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
