# 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, StrictStr
from typing import Any, ClassVar, Dict, List
from icat_plus_client.models.ewoks_session_id_jobs_post_request import EwoksSessionIdJobsPostRequest
from icat_plus_client.models.json_datacite_dates_inner import JsonDataciteDatesInner
from icat_plus_client.models.json_datacite_subjects_inner import JsonDataciteSubjectsInner
from icat_plus_client.models.json_datacite_titles import JsonDataciteTitles
from typing import Optional, Set
from typing_extensions import Self

class JsonDatacite(BaseModel):
    """
    JsonDatacite
    """ # noqa: E501
    doi: StrictStr
    url: StrictStr
    publication_year: StrictStr = Field(alias="publicationYear")
    creators: List[EwoksSessionIdJobsPostRequest]
    titles: JsonDataciteTitles
    publisher: StrictStr
    subjects: List[JsonDataciteSubjectsInner]
    dates: List[JsonDataciteDatesInner]
    __properties: ClassVar[List[str]] = ["doi", "url", "publicationYear", "creators", "titles", "publisher", "subjects", "dates"]

    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 JsonDatacite 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 creators (list)
        _items = []
        if self.creators:
            for _item_creators in self.creators:
                if _item_creators:
                    _items.append(_item_creators.to_dict())
            _dict['creators'] = _items
        # override the default output from pydantic by calling `to_dict()` of titles
        if self.titles:
            _dict['titles'] = self.titles.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in subjects (list)
        _items = []
        if self.subjects:
            for _item_subjects in self.subjects:
                if _item_subjects:
                    _items.append(_item_subjects.to_dict())
            _dict['subjects'] = _items
        # override the default output from pydantic by calling `to_dict()` of each item in dates (list)
        _items = []
        if self.dates:
            for _item_dates in self.dates:
                if _item_dates:
                    _items.append(_item_dates.to_dict())
            _dict['dates'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "doi": obj.get("doi"),
            "url": obj.get("url"),
            "publicationYear": obj.get("publicationYear"),
            "creators": [EwoksSessionIdJobsPostRequest.from_dict(_item) for _item in obj["creators"]] if obj.get("creators") is not None else None,
            "titles": JsonDataciteTitles.from_dict(obj["titles"]) if obj.get("titles") is not None else None,
            "publisher": obj.get("publisher"),
            "subjects": [JsonDataciteSubjectsInner.from_dict(_item) for _item in obj["subjects"]] if obj.get("subjects") is not None else None,
            "dates": [JsonDataciteDatesInner.from_dict(_item) for _item in obj["dates"]] if obj.get("dates") is not None else None
        })
        return _obj


