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.bulk_bag_dto_packet_format import BulkBagDtoPacketFormat
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.bag_item_dto import BagItemDto
    from ..models.bulk_bag_dto_validation_errors import BulkBagDtoValidationErrors


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


@_attrs_define
class BulkBagDto:
    """
    Attributes:
        id (int | Unset):
        country_code (str | Unset):
        customer_bag_id (str | Unset):
        packet_format (BulkBagDtoPacketFormat | Unset):
        item_count (int | Unset):
        total_weight (float | Unset):
        validation_errors (BulkBagDtoValidationErrors | Unset):
        customer_reference (str | Unset):
        shipment_type (str | Unset):
        bag_tracking (bool | Unset):
        auth_user (str | Unset):
        printed (bool | Unset):
        ui_row_selected (bool | Unset):
        number (int | Unset):
        items (list[BagItemDto] | Unset):
        linked_item_count (int | Unset):
        weight_per_item (float | Unset):
    """

    id: int | Unset = UNSET
    country_code: str | Unset = UNSET
    customer_bag_id: str | Unset = UNSET
    packet_format: BulkBagDtoPacketFormat | Unset = UNSET
    item_count: int | Unset = UNSET
    total_weight: float | Unset = UNSET
    validation_errors: BulkBagDtoValidationErrors | Unset = UNSET
    customer_reference: str | Unset = UNSET
    shipment_type: str | Unset = UNSET
    bag_tracking: bool | Unset = UNSET
    auth_user: str | Unset = UNSET
    printed: bool | Unset = UNSET
    ui_row_selected: bool | Unset = UNSET
    number: int | Unset = UNSET
    items: list[BagItemDto] | Unset = UNSET
    linked_item_count: int | Unset = UNSET
    weight_per_item: float | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        country_code = self.country_code

        customer_bag_id = self.customer_bag_id

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

        item_count = self.item_count

        total_weight = self.total_weight

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

        customer_reference = self.customer_reference

        shipment_type = self.shipment_type

        bag_tracking = self.bag_tracking

        auth_user = self.auth_user

        printed = self.printed

        ui_row_selected = self.ui_row_selected

        number = self.number

        items: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.items, Unset):
            items = []
            for items_item_data in self.items:
                items_item = items_item_data.to_dict()
                items.append(items_item)

        linked_item_count = self.linked_item_count

        weight_per_item = self.weight_per_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 country_code is not UNSET:
            field_dict["countryCode"] = country_code
        if customer_bag_id is not UNSET:
            field_dict["customerBagId"] = customer_bag_id
        if packet_format is not UNSET:
            field_dict["packetFormat"] = packet_format
        if item_count is not UNSET:
            field_dict["itemCount"] = item_count
        if total_weight is not UNSET:
            field_dict["totalWeight"] = total_weight
        if validation_errors is not UNSET:
            field_dict["validationErrors"] = validation_errors
        if customer_reference is not UNSET:
            field_dict["customerReference"] = customer_reference
        if shipment_type is not UNSET:
            field_dict["shipmentType"] = shipment_type
        if bag_tracking is not UNSET:
            field_dict["bagTracking"] = bag_tracking
        if auth_user is not UNSET:
            field_dict["authUser"] = auth_user
        if printed is not UNSET:
            field_dict["printed"] = printed
        if ui_row_selected is not UNSET:
            field_dict["uiRowSelected"] = ui_row_selected
        if number is not UNSET:
            field_dict["number"] = number
        if items is not UNSET:
            field_dict["items"] = items
        if linked_item_count is not UNSET:
            field_dict["linkedItemCount"] = linked_item_count
        if weight_per_item is not UNSET:
            field_dict["weightPerItem"] = weight_per_item

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.bag_item_dto import BagItemDto
        from ..models.bulk_bag_dto_validation_errors import BulkBagDtoValidationErrors

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

        country_code = d.pop("countryCode", UNSET)

        customer_bag_id = d.pop("customerBagId", UNSET)

        _packet_format = d.pop("packetFormat", UNSET)
        packet_format: BulkBagDtoPacketFormat | Unset
        if isinstance(_packet_format, Unset):
            packet_format = UNSET
        else:
            packet_format = BulkBagDtoPacketFormat(_packet_format)

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

        total_weight = d.pop("totalWeight", UNSET)

        _validation_errors = d.pop("validationErrors", UNSET)
        validation_errors: BulkBagDtoValidationErrors | Unset
        if isinstance(_validation_errors, Unset):
            validation_errors = UNSET
        else:
            validation_errors = BulkBagDtoValidationErrors.from_dict(_validation_errors)

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

        shipment_type = d.pop("shipmentType", UNSET)

        bag_tracking = d.pop("bagTracking", UNSET)

        auth_user = d.pop("authUser", UNSET)

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

        ui_row_selected = d.pop("uiRowSelected", UNSET)

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

        _items = d.pop("items", UNSET)
        items: list[BagItemDto] | Unset = UNSET
        if _items is not UNSET:
            items = []
            for items_item_data in _items:
                items_item = BagItemDto.from_dict(items_item_data)

                items.append(items_item)

        linked_item_count = d.pop("linkedItemCount", UNSET)

        weight_per_item = d.pop("weightPerItem", UNSET)

        bulk_bag_dto = cls(
            id=id,
            country_code=country_code,
            customer_bag_id=customer_bag_id,
            packet_format=packet_format,
            item_count=item_count,
            total_weight=total_weight,
            validation_errors=validation_errors,
            customer_reference=customer_reference,
            shipment_type=shipment_type,
            bag_tracking=bag_tracking,
            auth_user=auth_user,
            printed=printed,
            ui_row_selected=ui_row_selected,
            number=number,
            items=items,
            linked_item_count=linked_item_count,
            weight_per_item=weight_per_item,
        )

        bulk_bag_dto.additional_properties = d
        return bulk_bag_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
