# coding: utf-8

"""
Root Signals API

Root Signals JSON API provides a way to access Root Signals using provisioned API token

The version of the OpenAPI document: 1.0.0 (latest)
Generated by OpenAPI Generator (https://openapi-generator.tech)

Do not edit the class manually.
"""  # noqa: E501

from __future__ import annotations

import json
import pprint
import re  # noqa: F401
from typing import Any, ClassVar, Dict, List, Optional, Set, Union

from pydantic import BaseModel, ConfigDict, StrictBool, StrictFloat, StrictInt, StrictStr
from typing_extensions import Self

from root.generated.openapi_aclient.models.validation_result_status import ValidationResultStatus


class ValidatorResult(BaseModel):
    """
    ValidatorResult
    """  # noqa: E501

    evaluator_name: Optional[StrictStr] = None
    evaluator_id: StrictStr
    result: Optional[Union[StrictFloat, StrictInt]] = None
    threshold: Optional[Union[StrictFloat, StrictInt]] = None
    cost: Optional[Union[StrictFloat, StrictInt]] = None
    is_valid: Optional[StrictBool] = None
    status: Optional[ValidationResultStatus] = None
    justification: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = [
        "evaluator_name",
        "evaluator_id",
        "result",
        "threshold",
        "cost",
        "is_valid",
        "status",
        "justification",
    ]

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "evaluator_name": obj.get("evaluator_name"),
                "evaluator_id": obj.get("evaluator_id"),
                "result": obj.get("result"),
                "threshold": obj.get("threshold"),
                "cost": obj.get("cost"),
                "is_valid": obj.get("is_valid"),
                "status": obj.get("status"),
                "justification": obj.get("justification"),
            }
        )
        return _obj
