from __future__ import annotations

import datetime
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 dateutil.parser import isoparse

from ..models.bulk_order_dto_bulk_order_type import BulkOrderDtoBulkOrderType
from ..models.bulk_order_dto_order_classification import BulkOrderDtoOrderClassification
from ..models.bulk_order_dto_product_type import BulkOrderDtoProductType
from ..models.bulk_order_dto_status import BulkOrderDtoStatus
from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.bulk_bag_dto import BulkBagDto


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


@_attrs_define
class BulkOrderDto:
    """
    Attributes:
        id (int | Unset):
        contact_name (str | Unset):
        phone_number (str | Unset):
        job_reference (str | Unset):
        product_type (BulkOrderDtoProductType | Unset):
        bulk_order_type (BulkOrderDtoBulkOrderType | Unset):
        awb (str | Unset):
        bulk_bags (list[BulkBagDto] | Unset):
        status (BulkOrderDtoStatus | Unset):
        validation_errors (bool | Unset):  Default: False.
        error_message (str | Unset):
        number_of_copies (int | Unset):
        download_token (str | Unset):
        printable (bool | Unset):
        order_classification (BulkOrderDtoOrderClassification | Unset):
        created_at (datetime.datetime | Unset):
        created_by (str | Unset):
        auth_user (str | Unset):
        send_date (datetime.datetime | Unset):
        submitted_date (datetime.datetime | Unset):
        preadvice_eligible (bool | Unset):
        finalised (bool | Unset):
        total_item_weight_sum (float | Unset):
    """

    id: int | Unset = UNSET
    contact_name: str | Unset = UNSET
    phone_number: str | Unset = UNSET
    job_reference: str | Unset = UNSET
    product_type: BulkOrderDtoProductType | Unset = UNSET
    bulk_order_type: BulkOrderDtoBulkOrderType | Unset = UNSET
    awb: str | Unset = UNSET
    bulk_bags: list[BulkBagDto] | Unset = UNSET
    status: BulkOrderDtoStatus | Unset = UNSET
    validation_errors: bool | Unset = False
    error_message: str | Unset = UNSET
    number_of_copies: int | Unset = UNSET
    download_token: str | Unset = UNSET
    printable: bool | Unset = UNSET
    order_classification: BulkOrderDtoOrderClassification | Unset = UNSET
    created_at: datetime.datetime | Unset = UNSET
    created_by: str | Unset = UNSET
    auth_user: str | Unset = UNSET
    send_date: datetime.datetime | Unset = UNSET
    submitted_date: datetime.datetime | Unset = UNSET
    preadvice_eligible: bool | Unset = UNSET
    finalised: bool | Unset = UNSET
    total_item_weight_sum: float | Unset = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

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

        contact_name = self.contact_name

        phone_number = self.phone_number

        job_reference = self.job_reference

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

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

        awb = self.awb

        bulk_bags: list[dict[str, Any]] | Unset = UNSET
        if not isinstance(self.bulk_bags, Unset):
            bulk_bags = []
            for bulk_bags_item_data in self.bulk_bags:
                bulk_bags_item = bulk_bags_item_data.to_dict()
                bulk_bags.append(bulk_bags_item)

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

        validation_errors = self.validation_errors

        error_message = self.error_message

        number_of_copies = self.number_of_copies

        download_token = self.download_token

        printable = self.printable

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

        created_at: str | Unset = UNSET
        if not isinstance(self.created_at, Unset):
            created_at = self.created_at.isoformat()

        created_by = self.created_by

        auth_user = self.auth_user

        send_date: str | Unset = UNSET
        if not isinstance(self.send_date, Unset):
            send_date = self.send_date.isoformat()

        submitted_date: str | Unset = UNSET
        if not isinstance(self.submitted_date, Unset):
            submitted_date = self.submitted_date.isoformat()

        preadvice_eligible = self.preadvice_eligible

        finalised = self.finalised

        total_item_weight_sum = self.total_item_weight_sum

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update({})
        if id is not UNSET:
            field_dict["id"] = id
        if contact_name is not UNSET:
            field_dict["contactName"] = contact_name
        if phone_number is not UNSET:
            field_dict["phoneNumber"] = phone_number
        if job_reference is not UNSET:
            field_dict["jobReference"] = job_reference
        if product_type is not UNSET:
            field_dict["productType"] = product_type
        if bulk_order_type is not UNSET:
            field_dict["bulkOrderType"] = bulk_order_type
        if awb is not UNSET:
            field_dict["awb"] = awb
        if bulk_bags is not UNSET:
            field_dict["bulkBags"] = bulk_bags
        if status is not UNSET:
            field_dict["status"] = status
        if validation_errors is not UNSET:
            field_dict["validationErrors"] = validation_errors
        if error_message is not UNSET:
            field_dict["errorMessage"] = error_message
        if number_of_copies is not UNSET:
            field_dict["numberOfCopies"] = number_of_copies
        if download_token is not UNSET:
            field_dict["downloadToken"] = download_token
        if printable is not UNSET:
            field_dict["printable"] = printable
        if order_classification is not UNSET:
            field_dict["orderClassification"] = order_classification
        if created_at is not UNSET:
            field_dict["createdAt"] = created_at
        if created_by is not UNSET:
            field_dict["createdBy"] = created_by
        if auth_user is not UNSET:
            field_dict["authUser"] = auth_user
        if send_date is not UNSET:
            field_dict["sendDate"] = send_date
        if submitted_date is not UNSET:
            field_dict["submittedDate"] = submitted_date
        if preadvice_eligible is not UNSET:
            field_dict["preadviceEligible"] = preadvice_eligible
        if finalised is not UNSET:
            field_dict["finalised"] = finalised
        if total_item_weight_sum is not UNSET:
            field_dict["totalItemWeightSum"] = total_item_weight_sum

        return field_dict

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

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

        contact_name = d.pop("contactName", UNSET)

        phone_number = d.pop("phoneNumber", UNSET)

        job_reference = d.pop("jobReference", UNSET)

        _product_type = d.pop("productType", UNSET)
        product_type: BulkOrderDtoProductType | Unset
        if isinstance(_product_type, Unset):
            product_type = UNSET
        else:
            product_type = BulkOrderDtoProductType(_product_type)

        _bulk_order_type = d.pop("bulkOrderType", UNSET)
        bulk_order_type: BulkOrderDtoBulkOrderType | Unset
        if isinstance(_bulk_order_type, Unset):
            bulk_order_type = UNSET
        else:
            bulk_order_type = BulkOrderDtoBulkOrderType(_bulk_order_type)

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

        _bulk_bags = d.pop("bulkBags", UNSET)
        bulk_bags: list[BulkBagDto] | Unset = UNSET
        if _bulk_bags is not UNSET:
            bulk_bags = []
            for bulk_bags_item_data in _bulk_bags:
                bulk_bags_item = BulkBagDto.from_dict(bulk_bags_item_data)

                bulk_bags.append(bulk_bags_item)

        _status = d.pop("status", UNSET)
        status: BulkOrderDtoStatus | Unset
        if isinstance(_status, Unset):
            status = UNSET
        else:
            status = BulkOrderDtoStatus(_status)

        validation_errors = d.pop("validationErrors", UNSET)

        error_message = d.pop("errorMessage", UNSET)

        number_of_copies = d.pop("numberOfCopies", UNSET)

        download_token = d.pop("downloadToken", UNSET)

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

        _order_classification = d.pop("orderClassification", UNSET)
        order_classification: BulkOrderDtoOrderClassification | Unset
        if isinstance(_order_classification, Unset):
            order_classification = UNSET
        else:
            order_classification = BulkOrderDtoOrderClassification(_order_classification)

        _created_at = d.pop("createdAt", UNSET)
        created_at: datetime.datetime | Unset
        if isinstance(_created_at, Unset):
            created_at = UNSET
        else:
            created_at = isoparse(_created_at)

        created_by = d.pop("createdBy", UNSET)

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

        _send_date = d.pop("sendDate", UNSET)
        send_date: datetime.datetime | Unset
        if isinstance(_send_date, Unset):
            send_date = UNSET
        else:
            send_date = isoparse(_send_date)

        _submitted_date = d.pop("submittedDate", UNSET)
        submitted_date: datetime.datetime | Unset
        if isinstance(_submitted_date, Unset):
            submitted_date = UNSET
        else:
            submitted_date = isoparse(_submitted_date)

        preadvice_eligible = d.pop("preadviceEligible", UNSET)

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

        total_item_weight_sum = d.pop("totalItemWeightSum", UNSET)

        bulk_order_dto = cls(
            id=id,
            contact_name=contact_name,
            phone_number=phone_number,
            job_reference=job_reference,
            product_type=product_type,
            bulk_order_type=bulk_order_type,
            awb=awb,
            bulk_bags=bulk_bags,
            status=status,
            validation_errors=validation_errors,
            error_message=error_message,
            number_of_copies=number_of_copies,
            download_token=download_token,
            printable=printable,
            order_classification=order_classification,
            created_at=created_at,
            created_by=created_by,
            auth_user=auth_user,
            send_date=send_date,
            submitted_date=submitted_date,
            preadvice_eligible=preadvice_eligible,
            finalised=finalised,
            total_item_weight_sum=total_item_weight_sum,
        )

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