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


class PPIStringNetworkQuerySchema(BaseModel):
    """
    Schema for STRING network query parameters.
    """  # noqa: E501

    locus_tag: Optional[StrictStr] = None
    pair_id: Optional[StrictStr] = None
    protein_ids: Optional[List[StrictStr]] = None
    species_acronym: Optional[StrictStr] = None
    required_score: Optional[Annotated[int, Field(le=1000, strict=True, ge=0)]] = None
    add_nodes: Optional[Annotated[int, Field(strict=True, ge=0)]] = None
    network_type: Optional[StrictStr] = Field(
        default="physical",
        description="Network type: physical (direct interactions) or functional (physical + indirect associations)",
    )
    evidence_channels: Optional[List[StrictStr]] = None
    __properties: ClassVar[List[str]] = [
        "locus_tag",
        "pair_id",
        "protein_ids",
        "species_acronym",
        "required_score",
        "add_nodes",
        "network_type",
        "evidence_channels",
    ]

    @field_validator("network_type")
    def network_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(["physical", "functional"]):
            raise ValueError("must be one of enum values ('physical', 'functional')")
        return value

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "locus_tag": obj.get("locus_tag"),
                "pair_id": obj.get("pair_id"),
                "protein_ids": obj.get("protein_ids"),
                "species_acronym": obj.get("species_acronym"),
                "required_score": obj.get("required_score"),
                "add_nodes": obj.get("add_nodes"),
                "network_type": obj.get("network_type")
                if obj.get("network_type") is not None
                else "physical",
                "evidence_channels": obj.get("evidence_channels"),
            }
        )
        return _obj
