# coding: utf-8

"""
    Synapse DB

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

    The version of the OpenAPI document: 0.6.9
    Generated by OpenAPI Generator (https://openapi-generator.tech)

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


from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set

from pydantic import BaseModel, ConfigDict, Field, StrictStr
from syndb_api_client.models.data_license import DataLicense
from syndb_api_client.models.model_animal import ModelAnimal
from syndb_api_client.models.mutation_model_create_read import MutationModelCreateRead
from typing_extensions import Annotated, Self


class SingleDatasetSchemaNoBrainRegion(BaseModel):
    """
    SingleDatasetSchemaNoBrainRegion
    """  # noqa: E501

    authorized_group_names: Optional[List[StrictStr]] = None
    dataset_collection_names: Optional[List[StrictStr]] = None
    publication_dois: Optional[List[StrictStr]] = None
    id: StrictStr
    label: Annotated[str, Field(strict=True, max_length=120)]
    data_license: Optional[DataLicense] = None
    animal: ModelAnimal
    mutations: Optional[List[MutationModelCreateRead]] = None
    microscopy: StrictStr
    notes: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "authorized_group_names",
        "dataset_collection_names",
        "publication_dois",
        "id",
        "label",
        "data_license",
        "animal",
        "mutations",
        "microscopy",
        "notes",
    ]

    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 SingleDatasetSchemaNoBrainRegion 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 mutations (list)
        _items = []
        if self.mutations:
            for _item in self.mutations:
                if _item:
                    _items.append(_item.to_dict())
            _dict["mutations"] = _items
        # set to None if authorized_group_names (nullable) is None
        # and model_fields_set contains the field
        if self.authorized_group_names is None and "authorized_group_names" in self.model_fields_set:
            _dict["authorized_group_names"] = None

        # set to None if dataset_collection_names (nullable) is None
        # and model_fields_set contains the field
        if self.dataset_collection_names is None and "dataset_collection_names" in self.model_fields_set:
            _dict["dataset_collection_names"] = None

        # set to None if publication_dois (nullable) is None
        # and model_fields_set contains the field
        if self.publication_dois is None and "publication_dois" in self.model_fields_set:
            _dict["publication_dois"] = None

        # set to None if mutations (nullable) is None
        # and model_fields_set contains the field
        if self.mutations is None and "mutations" in self.model_fields_set:
            _dict["mutations"] = None

        # set to None if notes (nullable) is None
        # and model_fields_set contains the field
        if self.notes is None and "notes" in self.model_fields_set:
            _dict["notes"] = None

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "authorized_group_names": obj.get("authorized_group_names"),
                "dataset_collection_names": obj.get("dataset_collection_names"),
                "publication_dois": obj.get("publication_dois"),
                "id": obj.get("id"),
                "label": obj.get("label"),
                "data_license": obj.get("data_license"),
                "animal": obj.get("animal"),
                "mutations": (
                    [MutationModelCreateRead.from_dict(_item) for _item in obj["mutations"]]
                    if obj.get("mutations") is not None
                    else None
                ),
                "microscopy": obj.get("microscopy"),
                "notes": obj.get("notes"),
            }
        )
        return _obj
