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

class DrugMICSearchQuerySchema(BaseModel):
    """
    Query schema for drug MIC search.
    """ # noqa: E501
    query: Optional[StrictStr] = Field(default='', description="Search term for drug name, class, or strain")
    drug_name: Optional[StrictStr] = None
    drug_class: Optional[StrictStr] = None
    species_acronym: Optional[StrictStr] = None
    min_mic_value: Optional[Union[StrictFloat, StrictInt]] = None
    max_mic_value: Optional[Union[StrictFloat, StrictInt]] = None
    unit: Optional[StrictStr] = None
    experimental_condition: Optional[StrictStr] = None
    page: Optional[StrictInt] = Field(default=1, description="Page number")
    per_page: Optional[StrictInt] = Field(default=20, description="Number of results per page")
    sort_by: Optional[StrictStr] = None
    sort_order: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["query", "drug_name", "drug_class", "species_acronym", "min_mic_value", "max_mic_value", "unit", "experimental_condition", "page", "per_page", "sort_by", "sort_order"]

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "query": obj.get("query") if obj.get("query") is not None else '',
            "drug_name": obj.get("drug_name"),
            "drug_class": obj.get("drug_class"),
            "species_acronym": obj.get("species_acronym"),
            "min_mic_value": obj.get("min_mic_value"),
            "max_mic_value": obj.get("max_mic_value"),
            "unit": obj.get("unit"),
            "experimental_condition": obj.get("experimental_condition"),
            "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,
            "sort_by": obj.get("sort_by"),
            "sort_order": obj.get("sort_order")
        })
        return _obj


