# 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, StrictStr
from syndb_api_client.models.brain_region_read import BrainRegionRead
from syndb_api_client.models.cultural_model_animal_name import CulturalModelAnimalName
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_read import MutationModelRead
from syndb_api_client.models.syndb_table import SyndbTable
from typing_extensions import Self


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

    authorized_group_names: Optional[List[StrictStr]] = None
    dataset_collection_names: Optional[List[StrictStr]] = None
    publication_dois: Optional[List[StrictStr]] = None
    syndb_tables: Optional[List[SyndbTable]] = None
    data_licenses: Optional[List[DataLicense]] = None
    animals_species: Optional[List[ModelAnimal]] = None
    animal_cultural_names: Optional[List[CulturalModelAnimalName]] = None
    mutations: Optional[List[MutationModelRead]] = None
    brain_regions: Optional[List[BrainRegionRead]] = None
    microscopy_names: Optional[List[StrictStr]] = None
    owner_id: Optional[List[StrictStr]] = None
    __properties: ClassVar[List[str]] = [
        "authorized_group_names",
        "dataset_collection_names",
        "publication_dois",
        "syndb_tables",
        "data_licenses",
        "animals_species",
        "animal_cultural_names",
        "mutations",
        "brain_regions",
        "microscopy_names",
        "owner_id",
    ]

    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 DatasetFilterSchema 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
        # override the default output from pydantic by calling `to_dict()` of each item in brain_regions (list)
        _items = []
        if self.brain_regions:
            for _item in self.brain_regions:
                if _item:
                    _items.append(_item.to_dict())
            _dict["brain_regions"] = _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 syndb_tables (nullable) is None
        # and model_fields_set contains the field
        if self.syndb_tables is None and "syndb_tables" in self.model_fields_set:
            _dict["syndb_tables"] = None

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

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

        # set to None if animal_cultural_names (nullable) is None
        # and model_fields_set contains the field
        if self.animal_cultural_names is None and "animal_cultural_names" in self.model_fields_set:
            _dict["animal_cultural_names"] = 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 brain_regions (nullable) is None
        # and model_fields_set contains the field
        if self.brain_regions is None and "brain_regions" in self.model_fields_set:
            _dict["brain_regions"] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of DatasetFilterSchema 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"),
                "syndb_tables": obj.get("syndb_tables"),
                "data_licenses": obj.get("data_licenses"),
                "animals_species": obj.get("animals_species"),
                "animal_cultural_names": obj.get("animal_cultural_names"),
                "mutations": (
                    [MutationModelRead.from_dict(_item) for _item in obj["mutations"]]
                    if obj.get("mutations") is not None
                    else None
                ),
                "brain_regions": (
                    [BrainRegionRead.from_dict(_item) for _item in obj["brain_regions"]]
                    if obj.get("brain_regions") is not None
                    else None
                ),
                "microscopy_names": obj.get("microscopy_names"),
                "owner_id": obj.get("owner_id"),
            }
        )
        return _obj
