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

class PPISearchQuerySchema(BaseModel):
    """
    Schema for PPI search queries.
    """ # noqa: E501
    species_acronym: Optional[StrictStr] = None
    isolate_name: Optional[StrictStr] = None
    score_type: Optional[StrictStr] = None
    score_threshold: Optional[Union[StrictFloat, StrictInt]] = None
    has_xlms: Optional[StrictBool] = None
    has_string: Optional[StrictBool] = None
    has_operon: Optional[StrictBool] = None
    has_ecocyc: Optional[StrictBool] = None
    protein_id: Optional[StrictStr] = None
    locus_tag: Optional[StrictStr] = None
    page: Optional[Annotated[int, Field(strict=True, ge=1)]] = Field(default=1, description="Page number")
    per_page: Optional[Annotated[int, Field(le=100000, strict=True, ge=1)]] = Field(default=20, description="Results per page")
    __properties: ClassVar[List[str]] = ["species_acronym", "isolate_name", "score_type", "score_threshold", "has_xlms", "has_string", "has_operon", "has_ecocyc", "protein_id", "locus_tag", "page", "per_page"]

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

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

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

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

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

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

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

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

        # 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

        return _dict

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

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

        _obj = cls.model_validate({
            "species_acronym": obj.get("species_acronym"),
            "isolate_name": obj.get("isolate_name"),
            "score_type": obj.get("score_type"),
            "score_threshold": obj.get("score_threshold"),
            "has_xlms": obj.get("has_xlms"),
            "has_string": obj.get("has_string"),
            "has_operon": obj.get("has_operon"),
            "has_ecocyc": obj.get("has_ecocyc"),
            "protein_id": obj.get("protein_id"),
            "locus_tag": obj.get("locus_tag"),
            "page": obj.get("page") if obj.get("page") is not None else 1,
            "per_page": obj.get("per_page") if obj.get("per_page") is not None else 20
        })
        return _obj


