# coding: utf-8

"""
ME TT DataPortal Data Portal API

ME TT DataPortal Data Portal APIs to fetch Gut Microbes Genomes / Genes information.

The version of the OpenAPI document: 1.0.0
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,
    StrictBool,
    StrictFloat,
    StrictInt,
    StrictStr,
)
from typing import Any, ClassVar, Dict, List, Optional, Union
from typing import Set
from typing_extensions import Self


class DrugMetabolismDataSchema(BaseModel):
    """
    Schema for individual drug metabolism measurement.
    """  # noqa: E501

    drug_name: Optional[StrictStr] = None
    drug_class: Optional[StrictStr] = None
    drug_subclass: Optional[StrictStr] = None
    compound_name: Optional[StrictStr] = None
    pubchem_id: Optional[StrictStr] = None
    degr_percent: Optional[Union[StrictFloat, StrictInt]] = None
    pval: Optional[Union[StrictFloat, StrictInt]] = None
    fdr: Optional[Union[StrictFloat, StrictInt]] = None
    metabolizer_classification: Optional[StrictStr] = None
    is_significant: Optional[StrictBool] = None
    experimental_condition_id: Optional[StrictInt] = None
    experimental_condition_name: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "drug_name",
        "drug_class",
        "drug_subclass",
        "compound_name",
        "pubchem_id",
        "degr_percent",
        "pval",
        "fdr",
        "metabolizer_classification",
        "is_significant",
        "experimental_condition_id",
        "experimental_condition_name",
    ]

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "drug_name": obj.get("drug_name"),
                "drug_class": obj.get("drug_class"),
                "drug_subclass": obj.get("drug_subclass"),
                "compound_name": obj.get("compound_name"),
                "pubchem_id": obj.get("pubchem_id"),
                "degr_percent": obj.get("degr_percent"),
                "pval": obj.get("pval"),
                "fdr": obj.get("fdr"),
                "metabolizer_classification": obj.get("metabolizer_classification"),
                "is_significant": obj.get("is_significant"),
                "experimental_condition_id": obj.get("experimental_condition_id"),
                "experimental_condition_name": obj.get("experimental_condition_name"),
            }
        )
        return _obj
