# 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

from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing_extensions import Annotated, Self

from root.generated.openapi_client.models.generation_model_params_request import GenerationModelParamsRequest
from root.generated.openapi_client.models.visibility_enum import VisibilityEnum


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

    intent: Annotated[str, Field(min_length=10, strict=True, max_length=20000)]
    stage: Optional[StrictStr] = None
    visibility: VisibilityEnum
    file_id: Optional[StrictStr] = None
    extra_contexts: Optional[Dict[str, Optional[StrictStr]]] = None
    strict: Optional[StrictBool] = True
    generating_model_params: Optional[GenerationModelParamsRequest] = None
    __properties: ClassVar[List[str]] = [
        "intent",
        "stage",
        "visibility",
        "file_id",
        "extra_contexts",
        "strict",
        "generating_model_params",
    ]

    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 JudgeGeneratorRequest 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 generating_model_params
        if self.generating_model_params:
            _dict["generating_model_params"] = self.generating_model_params.to_dict()
        # set to None if stage (nullable) is None
        # and model_fields_set contains the field
        if self.stage is None and "stage" in self.model_fields_set:
            _dict["stage"] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate(
            {
                "intent": obj.get("intent"),
                "stage": obj.get("stage"),
                "visibility": obj.get("visibility"),
                "file_id": obj.get("file_id"),
                "extra_contexts": obj.get("extra_contexts"),
                "strict": obj.get("strict") if obj.get("strict") is not None else True,
                "generating_model_params": GenerationModelParamsRequest.from_dict(obj["generating_model_params"])
                if obj.get("generating_model_params") is not None
                else None,
            }
        )
        return _obj
