# coding: utf-8

"""
    seqq

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.0.18
    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 datetime import datetime
from pydantic import BaseModel, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from seqq.models.rpc_status import RpcStatus
from seqq.models.search_state import SearchState
from seqq.models.v1alpha_code import V1alphaCode
from seqq.models.v1alpha_hit import V1alphaHit
from typing import Optional, Set
from typing_extensions import Self

class V1alphaSearch(BaseModel):
    """
    A Search of the Sequences in a Collection.  On creation, Searches direct seqq to start a query against a Collection using a chosen `program`. On reads, Searches contain the results of the query, including its current `state` and any `hits`.
    """ # noqa: E501
    name: Optional[StrictStr] = Field(default=None, description="The globally unique name of the Serach. Format is `collections/{collection_id}/searches/{search_id}`.")
    query: StrictStr = Field(description="The sequence of nucleoties or amino acids to search the Collection for.")
    code: Optional[V1alphaCode] = None
    prefix: Optional[StrictStr] = Field(default=None, description="An optional \"/\" separated prefix to limit searches to.")
    query_time: Optional[datetime] = Field(default=None, description="The time a search start is started.", alias="queryTime")
    query_duration: Optional[StrictStr] = Field(default=None, description="The duration of a search from start to completion.", alias="queryDuration")
    hits: Optional[List[V1alphaHit]] = Field(default=None, description="A list of hits from the Search. This is only set when `state` is `SUCCEEDED`.")
    state: Optional[SearchState] = None
    error: Optional[RpcStatus] = None
    blastn: Optional[Dict[str, Any]] = Field(default=None, description="Blastn is a blastn search.")
    blastp: Optional[Dict[str, Any]] = Field(default=None, description="Blastp is a blastp search.")
    blastx: Optional[Dict[str, Any]] = Field(default=None, description="Blastp is a blastp search.")
    tblastn: Optional[Dict[str, Any]] = Field(default=None, description="Tblastn is a tblastn search.")
    tblastx: Optional[Dict[str, Any]] = Field(default=None, description="Tblastx is a tblastx search.")
    __properties: ClassVar[List[str]] = ["name", "query", "code", "prefix", "queryTime", "queryDuration", "hits", "state", "error", "blastn", "blastp", "blastx", "tblastn", "tblastx"]

    model_config = {
        "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 V1alphaSearch 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "query_time",
            "query_duration",
            "hits",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # override the default output from pydantic by calling `to_dict()` of each item in hits (list)
        _items = []
        if self.hits:
            for _item in self.hits:
                if _item:
                    _items.append(_item.to_dict())
            _dict['hits'] = _items
        # override the default output from pydantic by calling `to_dict()` of error
        if self.error:
            _dict['error'] = self.error.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "name": obj.get("name"),
            "query": obj.get("query"),
            "code": obj.get("code"),
            "prefix": obj.get("prefix"),
            "queryTime": obj.get("queryTime"),
            "queryDuration": obj.get("queryDuration"),
            "hits": [V1alphaHit.from_dict(_item) for _item in obj["hits"]] if obj.get("hits") is not None else None,
            "state": obj.get("state"),
            "error": RpcStatus.from_dict(obj["error"]) if obj.get("error") is not None else None,
            "blastn": obj.get("blastn"),
            "blastp": obj.get("blastp"),
            "blastx": obj.get("blastx"),
            "tblastn": obj.get("tblastn"),
            "tblastx": obj.get("tblastx")
        })
        return _obj


