# 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, Field, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Set
from typing_extensions import Self


class StringNetworkDataSchema(BaseModel):
    """
    Typed payload for STRING network API response (the `data` field).
    """  # noqa: E501

    network: Optional[List[Dict[str, Any]]] = Field(
        default=None,
        description="Raw STRING network edges (TSV rows as dicts with stringId_A/B, preferredName_A/B, scores, etc.)",
    )
    identifiers: Optional[List[StrictStr]] = Field(
        default=None, description="STRING protein IDs that were queried"
    )
    species_taxid: Optional[StrictInt] = None
    network_url: Optional[StrictStr] = None
    focal_locus_tag: Optional[StrictStr] = None
    focal_preferred_name: Optional[StrictStr] = None
    focal_string_id: Optional[StrictStr] = None
    data_sources: Optional[List[StrictStr]] = Field(
        default=None, description="Data source identifiers for multi-source graphs"
    )
    error: Optional[StrictStr] = None
    interaction: Optional[Dict[str, Any]] = None
    edges_filtered_unmapped: Optional[StrictInt] = None
    unmapped_string_ids: Optional[List[StrictStr]] = None
    __properties: ClassVar[List[str]] = [
        "network",
        "identifiers",
        "species_taxid",
        "network_url",
        "focal_locus_tag",
        "focal_preferred_name",
        "focal_string_id",
        "data_sources",
        "error",
        "interaction",
        "edges_filtered_unmapped",
        "unmapped_string_ids",
    ]

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "network": obj.get("network"),
                "identifiers": obj.get("identifiers"),
                "species_taxid": obj.get("species_taxid"),
                "network_url": obj.get("network_url"),
                "focal_locus_tag": obj.get("focal_locus_tag"),
                "focal_preferred_name": obj.get("focal_preferred_name"),
                "focal_string_id": obj.get("focal_string_id"),
                "data_sources": obj.get("data_sources"),
                "error": obj.get("error"),
                "interaction": obj.get("interaction"),
                "edges_filtered_unmapped": obj.get("edges_filtered_unmapped"),
                "unmapped_string_ids": obj.get("unmapped_string_ids"),
            }
        )
        return _obj
