from __future__ import annotations

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

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

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.paperwork import Paperwork


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


@_attrs_define
class AssembleOrder:
    """This assembles the items or bags to a new order. EITHER bagIds OR itemBarcodes is REQUIRED

    Example:
        {'itemBarcodes': ['BC123456789DE', 'BC123456790DE', 'BC123456791DE'], 'paperwork': {'contactName': 'John Doe',
            'awbCopyCount': 3}}

    Attributes:
        paperwork (Paperwork):  Example: {'contactName': 'John Doe', 'awbCopyCount': 3, 'jobReference': 'Job ref',
            'pickupType': 'CUSTOMER_DROP_OFF', 'telephoneNumber': '+4935120681234'}.
        item_barcodes (list[str] | Unset): An array of barcodes.
        bag_ids (list[str] | Unset): An array of bagIds. These identify the items that shall be assembled to bag new
            orders.
    """

    paperwork: Paperwork
    item_barcodes: list[str] | Unset = UNSET
    bag_ids: list[str] | 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()

        item_barcodes: list[str] | Unset = UNSET
        if not isinstance(self.item_barcodes, Unset):
            item_barcodes = self.item_barcodes

        bag_ids: list[str] | Unset = UNSET
        if not isinstance(self.bag_ids, Unset):
            bag_ids = self.bag_ids

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "paperwork": paperwork,
            }
        )
        if item_barcodes is not UNSET:
            field_dict["itemBarcodes"] = item_barcodes
        if bag_ids is not UNSET:
            field_dict["bagIds"] = bag_ids

        return field_dict

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

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

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

        bag_ids = cast(list[str], d.pop("bagIds", UNSET))

        assemble_order = cls(
            paperwork=paperwork,
            item_barcodes=item_barcodes,
            bag_ids=bag_ids,
        )

        assemble_order.additional_properties = d
        return assemble_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
