from __future__ import annotations

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

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

from ..types import UNSET, Unset

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


@_attrs_define
class Bag:
    """
    Attributes:
        bag_track (bool): False for bulk preadvice, True for bag tracking Default: False.
        format_ (str): The format of the content of this bag. Example: P.
        destination_country (str): The destination country code. Example: DE.
        items_count (int): Number of items in bag. Minimum 1.
        items_weight_in_kilogram (float): The weight in kilogram of the bag. Example: 100.
        id (int | Unset): Internal id of the bag.
        customer_reference (str | Unset): Customer reference Example: Customer reference.
    """

    format_: str
    destination_country: str
    items_count: int
    items_weight_in_kilogram: float
    bag_track: bool = False
    id: int | Unset = UNSET
    customer_reference: str | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        format_ = self.format_

        destination_country = self.destination_country

        items_count = self.items_count

        items_weight_in_kilogram = self.items_weight_in_kilogram

        id = self.id

        customer_reference = self.customer_reference

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "bagTrack": bag_track,
                "format": format_,
                "destinationCountry": destination_country,
                "itemsCount": items_count,
                "itemsWeightInKilogram": items_weight_in_kilogram,
            }
        )
        if id is not UNSET:
            field_dict["id"] = id
        if customer_reference is not UNSET:
            field_dict["customerReference"] = customer_reference

        return field_dict

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

        format_ = d.pop("format")

        destination_country = d.pop("destinationCountry")

        items_count = d.pop("itemsCount")

        items_weight_in_kilogram = d.pop("itemsWeightInKilogram")

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

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

        bag = cls(
            bag_track=bag_track,
            format_=format_,
            destination_country=destination_country,
            items_count=items_count,
            items_weight_in_kilogram=items_weight_in_kilogram,
            id=id,
            customer_reference=customer_reference,
        )

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