# coding: utf-8

"""
    Picteus

    The Picteus API

    The version of the OpenAPI document: 0.11.0
    Contact: edouard@koppasoft.com
    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
from typing import Any, ClassVar, Dict, List, Optional
from picteus_ws_client.models.image_format import ImageFormat
from picteus_ws_client.models.search_features import SearchFeatures
from picteus_ws_client.models.search_keyword import SearchKeyword
from picteus_ws_client.models.search_properties import SearchProperties
from picteus_ws_client.models.search_tags import SearchTags
from typing import Optional, Set
from typing_extensions import Self

class SearchCriteria(BaseModel):
    """
    Criteria when searching for images
    """ # noqa: E501
    formats: Optional[List[ImageFormat]] = Field(default=None, description="A filter used by the search which will limit the result entities to those having one of the provided image formats")
    keyword: Optional[SearchKeyword] = Field(default=None, description="A filter which limits the result entities with the provided text specifications")
    tags: Optional[SearchTags] = Field(default=None, description="A filter which limits the result entities with the provided tags specifications")
    features: Optional[SearchFeatures] = Field(default=None, description="A filter which limits the result entities with the provided features specifications")
    properties: Optional[SearchProperties] = Field(default=None, description="A filter which limits the result entities with the provided technical properties")
    __properties: ClassVar[List[str]] = ["formats", "keyword", "tags", "features", "properties"]

    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 SearchCriteria 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,
        )
        # override the default output from pydantic by calling `to_dict()` of keyword
        if self.keyword:
            _dict['keyword'] = self.keyword.to_dict()
        # override the default output from pydantic by calling `to_dict()` of tags
        if self.tags:
            _dict['tags'] = self.tags.to_dict()
        # override the default output from pydantic by calling `to_dict()` of features
        if self.features:
            _dict['features'] = self.features.to_dict()
        # override the default output from pydantic by calling `to_dict()` of properties
        if self.properties:
            _dict['properties'] = self.properties.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "formats": obj.get("formats"),
            "keyword": SearchKeyword.from_dict(obj["keyword"]) if obj.get("keyword") is not None else None,
            "tags": SearchTags.from_dict(obj["tags"]) if obj.get("tags") is not None else None,
            "features": SearchFeatures.from_dict(obj["features"]) if obj.get("features") is not None else None,
            "properties": SearchProperties.from_dict(obj["properties"]) if obj.get("properties") is not None else None
        })
        return _obj


