# coding: utf-8

"""
    Search API

    API for search functionality.

    The version of the OpenAPI document: 
    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, StrictBool, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from yfkm3_services_search_client.models.fusion_mode import FusionMode
from yfkm3_services_search_client.models.search_mode import SearchMode
from typing import Optional, Set
from typing_extensions import Self
from pydantic_core import to_jsonable_python

class SearchRequest(BaseModel):
    """
    SearchRequest
    """ # noqa: E501
    query: StrictStr
    space_id: StrictInt
    collection_ids: Optional[List[StrictInt]] = None
    mode: Optional[SearchMode] = None
    top_k: Optional[StrictInt] = 5
    candidate_top_k: Optional[StrictInt] = None
    vector_top_k: Optional[StrictInt] = None
    bm25_top_k: Optional[StrictInt] = None
    num_candidates: Optional[StrictInt] = None
    fusion_mode: Optional[FusionMode] = None
    rrf_k: Optional[StrictInt] = 60
    vector_weight: Optional[Union[StrictFloat, StrictInt]] = 0.5
    bm25_weight: Optional[Union[StrictFloat, StrictInt]] = 0.5
    document_type: Optional[StrictStr] = None
    document_id_list: Optional[List[StrictStr]] = None
    exclude_document_id_list: Optional[List[StrictStr]] = None
    exclude_paragraph_list: Optional[List[StrictStr]] = None
    query_vector: Optional[List[Union[StrictFloat, StrictInt]]] = None
    is_active: Optional[StrictBool] = None
    with_rerank: Optional[StrictBool] = False
    rerank_top_n: Optional[StrictInt] = None
    rerank_candidate_top_n: Optional[StrictInt] = None
    __properties: ClassVar[List[str]] = ["query", "space_id", "collection_ids", "mode", "top_k", "candidate_top_k", "vector_top_k", "bm25_top_k", "num_candidates", "fusion_mode", "rrf_k", "vector_weight", "bm25_weight", "document_type", "document_id_list", "exclude_document_id_list", "exclude_paragraph_list", "query_vector", "is_active", "with_rerank", "rerank_top_n", "rerank_candidate_top_n"]

    model_config = ConfigDict(
        validate_by_name=True,
        validate_by_alias=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"""
        return json.dumps(to_jsonable_python(self.to_dict()))

    @classmethod
    def from_json(cls, json_str: str) -> Optional[Self]:
        """Create an instance of SearchRequest 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 candidate_top_k (nullable) is None
        # and model_fields_set contains the field
        if self.candidate_top_k is None and "candidate_top_k" in self.model_fields_set:
            _dict['candidate_top_k'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SearchRequest 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"),
            "space_id": obj.get("space_id"),
            "collection_ids": obj.get("collection_ids"),
            "mode": obj.get("mode"),
            "top_k": obj.get("top_k") if obj.get("top_k") is not None else 5,
            "candidate_top_k": obj.get("candidate_top_k"),
            "vector_top_k": obj.get("vector_top_k"),
            "bm25_top_k": obj.get("bm25_top_k"),
            "num_candidates": obj.get("num_candidates"),
            "fusion_mode": obj.get("fusion_mode"),
            "rrf_k": obj.get("rrf_k") if obj.get("rrf_k") is not None else 60,
            "vector_weight": obj.get("vector_weight") if obj.get("vector_weight") is not None else 0.5,
            "bm25_weight": obj.get("bm25_weight") if obj.get("bm25_weight") is not None else 0.5,
            "document_type": obj.get("document_type"),
            "document_id_list": obj.get("document_id_list"),
            "exclude_document_id_list": obj.get("exclude_document_id_list"),
            "exclude_paragraph_list": obj.get("exclude_paragraph_list"),
            "query_vector": obj.get("query_vector"),
            "is_active": obj.get("is_active"),
            "with_rerank": obj.get("with_rerank") if obj.get("with_rerank") is not None else False,
            "rerank_top_n": obj.get("rerank_top_n"),
            "rerank_candidate_top_n": obj.get("rerank_candidate_top_n")
        })
        return _obj


