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

if TYPE_CHECKING:
    from ..models.bag import Bag
    from ..models.bag_paperwork import BagPaperwork


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


@_attrs_define
class BagOrder:
    """
    Attributes:
        paperwork (BagPaperwork):
        bags (list[Bag] | Unset): The bags associated with this order.
        customer_ekp (int | Unset):
        awb_id (int | Unset):
        net_bulk_weight_in_kilogram (float | Unset):  Example: 100.
        order_id (int | Unset):
        order_status (BagOrderOrderStatus | Unset):
    """

    paperwork: BagPaperwork
    bags: list[Bag] | Unset = UNSET
    customer_ekp: int | Unset = UNSET
    awb_id: int | Unset = UNSET
    net_bulk_weight_in_kilogram: float | Unset = UNSET
    order_id: int | Unset = UNSET
    order_status: BagOrderOrderStatus | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        bags: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.bags, Unset):
            bags = []
            for bags_item_data in self.bags:
                bags_item = bags_item_data.to_dict()
                bags.append(bags_item)

        customer_ekp = self.customer_ekp

        awb_id = self.awb_id

        net_bulk_weight_in_kilogram = self.net_bulk_weight_in_kilogram

        order_id = self.order_id

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

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "paperwork": paperwork,
            }
        )
        if bags is not UNSET:
            field_dict["bags"] = bags
        if customer_ekp is not UNSET:
            field_dict["customerEkp"] = customer_ekp
        if awb_id is not UNSET:
            field_dict["awbId"] = awb_id
        if net_bulk_weight_in_kilogram is not UNSET:
            field_dict["netBulkWeightInKilogram"] = net_bulk_weight_in_kilogram
        if order_id is not UNSET:
            field_dict["orderId"] = order_id
        if order_status is not UNSET:
            field_dict["orderStatus"] = order_status

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.bag import Bag
        from ..models.bag_paperwork import BagPaperwork

        d = dict(src_dict)
        paperwork = BagPaperwork.from_dict(d.pop("paperwork"))

        _bags = d.pop("bags", UNSET)
        bags: list[Bag] | Unset = UNSET
        if _bags is not UNSET:
            bags = []
            for bags_item_data in _bags:
                bags_item = Bag.from_dict(bags_item_data)

                bags.append(bags_item)

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

        awb_id = d.pop("awbId", UNSET)

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

        order_id = d.pop("orderId", UNSET)

        _order_status = d.pop("orderStatus", UNSET)
        order_status: BagOrderOrderStatus | Unset
        if isinstance(_order_status, Unset):
            order_status = UNSET
        else:
            order_status = BagOrderOrderStatus(_order_status)

        bag_order = cls(
            paperwork=paperwork,
            bags=bags,
            customer_ekp=customer_ekp,
            awb_id=awb_id,
            net_bulk_weight_in_kilogram=net_bulk_weight_in_kilogram,
            order_id=order_id,
            order_status=order_status,
        )

        bag_order.additional_properties = d
        return bag_order

    @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
