# coding: utf-8

"""
    Sonatype Lifecycle Public REST API

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 1.182.0-01
    Contact: community@sonatype.com
    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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from sonatype_iq_api_client.models.body_part_media_type import BodyPartMediaType
from sonatype_iq_api_client.models.content_disposition import ContentDisposition
from sonatype_iq_api_client.models.parameterized_header import ParameterizedHeader
from typing import Optional, Set
from typing_extensions import Self

class MultiPart(BaseModel):
    """
    MultiPart
    """ # noqa: E501
    body_parts: Optional[List[BodyPart]] = Field(default=None, alias="bodyParts")
    content_disposition: Optional[ContentDisposition] = Field(default=None, alias="contentDisposition")
    entity: Optional[Dict[str, Any]] = None
    headers: Optional[Dict[str, List[StrictStr]]] = None
    media_type: Optional[BodyPartMediaType] = Field(default=None, alias="mediaType")
    message_body_workers: Optional[Dict[str, Any]] = Field(default=None, alias="messageBodyWorkers")
    parameterized_headers: Optional[Dict[str, List[ParameterizedHeader]]] = Field(default=None, alias="parameterizedHeaders")
    parent: Optional[MultiPart] = None
    providers: Optional[Dict[str, Any]] = None
    __properties: ClassVar[List[str]] = ["bodyParts", "contentDisposition", "entity", "headers", "mediaType", "messageBodyWorkers", "parameterizedHeaders", "parent", "providers"]

    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 MultiPart 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 each item in body_parts (list)
        _items = []
        if self.body_parts:
            for _item_body_parts in self.body_parts:
                if _item_body_parts:
                    _items.append(_item_body_parts.to_dict())
            _dict['bodyParts'] = _items
        # override the default output from pydantic by calling `to_dict()` of content_disposition
        if self.content_disposition:
            _dict['contentDisposition'] = self.content_disposition.to_dict()
        # override the default output from pydantic by calling `to_dict()` of media_type
        if self.media_type:
            _dict['mediaType'] = self.media_type.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in parameterized_headers (dict of array)
        _field_dict_of_array = {}
        if self.parameterized_headers:
            for _key_parameterized_headers in self.parameterized_headers:
                if self.parameterized_headers[_key_parameterized_headers] is not None:
                    _field_dict_of_array[_key_parameterized_headers] = [
                        _item.to_dict() for _item in self.parameterized_headers[_key_parameterized_headers]
                    ]
            _dict['parameterizedHeaders'] = _field_dict_of_array
        # override the default output from pydantic by calling `to_dict()` of parent
        if self.parent:
            _dict['parent'] = self.parent.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "bodyParts": [BodyPart.from_dict(_item) for _item in obj["bodyParts"]] if obj.get("bodyParts") is not None else None,
            "contentDisposition": ContentDisposition.from_dict(obj["contentDisposition"]) if obj.get("contentDisposition") is not None else None,
            "entity": obj.get("entity"),
            "headers": obj.get("headers"),
            "mediaType": BodyPartMediaType.from_dict(obj["mediaType"]) if obj.get("mediaType") is not None else None,
            "messageBodyWorkers": obj.get("messageBodyWorkers"),
            "parameterizedHeaders": dict(
                (_k,
                        [ParameterizedHeader.from_dict(_item) for _item in _v]
                        if _v is not None
                        else None
                )
                for _k, _v in obj.get("parameterizedHeaders", {}).items()
            ),
            "parent": MultiPart.from_dict(obj["parent"]) if obj.get("parent") is not None else None,
            "providers": obj.get("providers")
        })
        return _obj

from sonatype_iq_api_client.models.body_part import BodyPart
# TODO: Rewrite to not use raise_errors
MultiPart.model_rebuild(raise_errors=False)

