# coding: utf-8

"""
    ICAT+ API

    ICAT+ RESTful API with Swagger

    The version of the OpenAPI document: 1.0.0
    Contact: demariaa@esrf.fr
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""  # noqa: E501


from __future__ import annotations
import pprint
import re  # noqa: F401
import json

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from icat_plus_client.models.address import Address
from icat_plus_client.models.investigation import Investigation
from icat_plus_client.models.item import Item
from icat_plus_client.models.meta import Meta
from icat_plus_client.models.return_parcel_information import ReturnParcelInformation
from icat_plus_client.models.status import Status
from icat_plus_client.models.tracking_information import TrackingInformation
from typing import Optional, Set
from typing_extensions import Self

class Parcel(BaseModel):
    """
    A box that will be sent by courier to the faciity with items inside and will be tracked independently.
    """ # noqa: E501
    id: Optional[StrictStr] = Field(default=None, alias="_id")
    shipment_id: Optional[StrictStr] = Field(default=None, alias="shipmentId")
    name: StrictStr
    investigation_id: Union[StrictFloat, StrictInt] = Field(alias="investigationId")
    investigation_name: StrictStr = Field(alias="investigationName")
    storage_conditions: Optional[StrictStr] = Field(default=None, alias="storageConditions")
    is_reimbursed: Optional[StrictBool] = Field(default=None, alias="isReimbursed")
    reimbursed_customs_value: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, alias="reimbursedCustomsValue")
    return_instructions: Optional[StrictStr] = Field(default=None, alias="returnInstructions")
    return_parcel_information: Optional[ReturnParcelInformation] = Field(default=None, alias="returnParcelInformation")
    comments: Optional[StrictStr] = None
    contains_dangerous_goods: Optional[StrictBool] = Field(default=None, alias="containsDangerousGoods")
    statuses: Optional[List[Status]] = None
    shipping_address: Optional[Address] = Field(default=None, alias="shippingAddress")
    return_address: Optional[Address] = Field(default=None, alias="returnAddress")
    shipping_tracking_information: Optional[TrackingInformation] = Field(default=None, alias="shippingTrackingInformation")
    return_tracking_information: Optional[TrackingInformation] = Field(default=None, alias="returnTrackingInformation")
    description: Optional[StrictStr] = None
    type: Optional[StrictStr] = None
    current_status: Optional[StrictStr] = Field(default=None, alias="currentStatus")
    items: Optional[List[Item]] = None
    local_contact_names: Optional[List[StrictStr]] = Field(default=None, alias="localContactNames")
    content: Optional[List[Item]] = None
    created_at: Optional[StrictStr] = Field(default=None, alias="createdAt")
    updated_at: Optional[StrictStr] = Field(default=None, alias="updatedAt")
    id: Optional[StrictStr] = None
    investigation: Optional[Investigation] = None
    meta: Optional[Meta] = None
    __properties: ClassVar[List[str]] = ["_id", "shipmentId", "name", "investigationId", "investigationName", "storageConditions", "isReimbursed", "reimbursedCustomsValue", "returnInstructions", "returnParcelInformation", "comments", "containsDangerousGoods", "statuses", "shippingAddress", "returnAddress", "shippingTrackingInformation", "returnTrackingInformation", "description", "type", "currentStatus", "items", "localContactNames", "content", "createdAt", "updatedAt", "id", "investigation", "meta"]

    model_config = ConfigDict(
        populate_by_name=True,
        validate_assignment=True,
        protected_namespaces=(),
    )


    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.model_dump(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of Parcel from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self) -> Dict[str, Any]:
        """Return the dictionary representation of the model using alias.

        This has the following differences from calling pydantic's
        `self.model_dump(by_alias=True)`:

        * `None` is only added to the output dict for nullable fields that
          were set at model initialization. Other fields with value `None`
          are ignored.
        """
        excluded_fields: Set[str] = set([
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of return_parcel_information
        if self.return_parcel_information:
            _dict['returnParcelInformation'] = self.return_parcel_information.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in statuses (list)
        _items = []
        if self.statuses:
            for _item_statuses in self.statuses:
                if _item_statuses:
                    _items.append(_item_statuses.to_dict())
            _dict['statuses'] = _items
        # override the default output from pydantic by calling `to_dict()` of shipping_address
        if self.shipping_address:
            _dict['shippingAddress'] = self.shipping_address.to_dict()
        # override the default output from pydantic by calling `to_dict()` of return_address
        if self.return_address:
            _dict['returnAddress'] = self.return_address.to_dict()
        # override the default output from pydantic by calling `to_dict()` of shipping_tracking_information
        if self.shipping_tracking_information:
            _dict['shippingTrackingInformation'] = self.shipping_tracking_information.to_dict()
        # override the default output from pydantic by calling `to_dict()` of return_tracking_information
        if self.return_tracking_information:
            _dict['returnTrackingInformation'] = self.return_tracking_information.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in items (list)
        _items = []
        if self.items:
            for _item_items in self.items:
                if _item_items:
                    _items.append(_item_items.to_dict())
            _dict['items'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in content (list)
        _items = []
        if self.content:
            for _item_content in self.content:
                if _item_content:
                    _items.append(_item_content.to_dict())
            _dict['content'] = _items
        # override the default output from pydantic by calling `to_dict()` of investigation
        if self.investigation:
            _dict['investigation'] = self.investigation.to_dict()
        # override the default output from pydantic by calling `to_dict()` of meta
        if self.meta:
            _dict['meta'] = self.meta.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Parcel from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return cls.model_validate(obj)

        _obj = cls.model_validate({
            "_id": obj.get("_id"),
            "shipmentId": obj.get("shipmentId"),
            "name": obj.get("name"),
            "investigationId": obj.get("investigationId"),
            "investigationName": obj.get("investigationName"),
            "storageConditions": obj.get("storageConditions"),
            "isReimbursed": obj.get("isReimbursed"),
            "reimbursedCustomsValue": obj.get("reimbursedCustomsValue"),
            "returnInstructions": obj.get("returnInstructions"),
            "returnParcelInformation": ReturnParcelInformation.from_dict(obj["returnParcelInformation"]) if obj.get("returnParcelInformation") is not None else None,
            "comments": obj.get("comments"),
            "containsDangerousGoods": obj.get("containsDangerousGoods"),
            "statuses": [Status.from_dict(_item) for _item in obj["statuses"]] if obj.get("statuses") is not None else None,
            "shippingAddress": Address.from_dict(obj["shippingAddress"]) if obj.get("shippingAddress") is not None else None,
            "returnAddress": Address.from_dict(obj["returnAddress"]) if obj.get("returnAddress") is not None else None,
            "shippingTrackingInformation": TrackingInformation.from_dict(obj["shippingTrackingInformation"]) if obj.get("shippingTrackingInformation") is not None else None,
            "returnTrackingInformation": TrackingInformation.from_dict(obj["returnTrackingInformation"]) if obj.get("returnTrackingInformation") is not None else None,
            "description": obj.get("description"),
            "type": obj.get("type"),
            "currentStatus": obj.get("currentStatus"),
            "items": [Item.from_dict(_item) for _item in obj["items"]] if obj.get("items") is not None else None,
            "localContactNames": obj.get("localContactNames"),
            "content": [Item.from_dict(_item) for _item in obj["content"]] if obj.get("content") is not None else None,
            "createdAt": obj.get("createdAt"),
            "updatedAt": obj.get("updatedAt"),
            "id": obj.get("id"),
            "investigation": Investigation.from_dict(obj["investigation"]) if obj.get("investigation") is not None else None,
            "meta": Meta.from_dict(obj["meta"]) if obj.get("meta") is not None else None
        })
        return _obj


