# coding: utf-8

"""
    AI Hub API

    The AI Hub REST API. See https://docs.instabase.com/api-sdk/ for more details.

    The version of the OpenAPI document: 0.1
    Contact: support@instabase.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, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from aihub.models.case_input_field import CaseInputField
from aihub.models.modification_object import ModificationObject
from typing import Optional, Set
from typing_extensions import Self

class CaseInfoField(BaseModel):
    """
    CaseInfoField
    """ # noqa: E501
    name: StrictStr = Field(description="Name of the case field.")
    value: StrictStr = Field(description="The value of the case field.")
    input_fields: Optional[List[CaseInputField]] = Field(default=None, description="Only applicable for ranked case fields. Input options the user can choose from when determining the value of this ranked field. ")
    chosen_field: Optional[CaseInputField] = None
    error_msg: Optional[StrictStr] = Field(default=None, description="Error message for the case field, if any.")
    edit_history: Optional[List[ModificationObject]] = Field(default=None, description="The history of edits to the case field. Returned when include_review_results=true.")
    __properties: ClassVar[List[str]] = ["name", "value", "input_fields", "chosen_field", "error_msg", "edit_history"]

    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 CaseInfoField 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 each item in input_fields (list)
        _items = []
        if self.input_fields:
            for _item_input_fields in self.input_fields:
                if _item_input_fields:
                    _items.append(_item_input_fields.to_dict())
            _dict['input_fields'] = _items
        # override the default output from pydantic by calling `to_dict()` of chosen_field
        if self.chosen_field:
            _dict['chosen_field'] = self.chosen_field.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in edit_history (list)
        _items = []
        if self.edit_history:
            for _item_edit_history in self.edit_history:
                if _item_edit_history:
                    _items.append(_item_edit_history.to_dict())
            _dict['edit_history'] = _items
        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CaseInfoField 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"),
            "value": obj.get("value"),
            "input_fields": [CaseInputField.from_dict(_item) for _item in obj["input_fields"]] if obj.get("input_fields") is not None else None,
            "chosen_field": CaseInputField.from_dict(obj["chosen_field"]) if obj.get("chosen_field") is not None else None,
            "error_msg": obj.get("error_msg"),
            "edit_history": [ModificationObject.from_dict(_item) for _item in obj["edit_history"]] if obj.get("edit_history") is not None else None
        })
        return _obj


