# 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.investigation_instrument import InvestigationInstrument
from icat_plus_client.models.investigation_investigation_users_inner import InvestigationInvestigationUsersInner
from icat_plus_client.models.investigation_type import InvestigationType
from icat_plus_client.models.meta import Meta
from typing import Optional, Set
from typing_extensions import Self

class Investigation(BaseModel):
    """
    Investigation
    """ # noqa: E501
    id: Union[StrictFloat, StrictInt]
    name: StrictStr
    start_date: StrictStr = Field(alias="startDate")
    end_date: Optional[StrictStr] = Field(default=None, alias="endDate")
    doi: Optional[StrictStr] = None
    title: Optional[StrictStr] = None
    visit_id: Optional[StrictStr] = Field(default=None, alias="visitId")
    release_date: Optional[StrictStr] = Field(default=None, alias="releaseDate")
    summary: Optional[StrictStr] = None
    parameters: Optional[Dict[str, Any]] = None
    instrument: Optional[InvestigationInstrument] = None
    investigation_users: Optional[List[InvestigationInvestigationUsersInner]] = Field(default=None, alias="investigationUsers")
    meta: Optional[Meta] = None
    type: Optional[InvestigationType] = None
    can_access_datasets: Optional[StrictBool] = Field(default=None, alias="canAccessDatasets")
    __properties: ClassVar[List[str]] = ["id", "name", "startDate", "endDate", "doi", "title", "visitId", "releaseDate", "summary", "parameters", "instrument", "investigationUsers", "meta", "type", "canAccessDatasets"]

    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 Investigation 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 instrument
        if self.instrument:
            _dict['instrument'] = self.instrument.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in investigation_users (list)
        _items = []
        if self.investigation_users:
            for _item_investigation_users in self.investigation_users:
                if _item_investigation_users:
                    _items.append(_item_investigation_users.to_dict())
            _dict['investigationUsers'] = _items
        # override the default output from pydantic by calling `to_dict()` of meta
        if self.meta:
            _dict['meta'] = self.meta.to_dict()
        # override the default output from pydantic by calling `to_dict()` of type
        if self.type:
            _dict['type'] = self.type.to_dict()
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of Investigation 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"),
            "name": obj.get("name"),
            "startDate": obj.get("startDate"),
            "endDate": obj.get("endDate"),
            "doi": obj.get("doi"),
            "title": obj.get("title"),
            "visitId": obj.get("visitId"),
            "releaseDate": obj.get("releaseDate"),
            "summary": obj.get("summary"),
            "parameters": obj.get("parameters"),
            "instrument": InvestigationInstrument.from_dict(obj["instrument"]) if obj.get("instrument") is not None else None,
            "investigationUsers": [InvestigationInvestigationUsersInner.from_dict(_item) for _item in obj["investigationUsers"]] if obj.get("investigationUsers") is not None else None,
            "meta": Meta.from_dict(obj["meta"]) if obj.get("meta") is not None else None,
            "type": InvestigationType.from_dict(obj["type"]) if obj.get("type") is not None else None,
            "canAccessDatasets": obj.get("canAccessDatasets")
        })
        return _obj


