# coding: utf-8

"""
    Rapidata Asset API

    The API for the Rapidata Asset service

    The version of the OpenAPI document: v1
    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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from rapidata.api_client.models.feature_flag import FeatureFlag
from typing import Optional, Set
from typing_extensions import Self

class CreateFlowEndpointInput(BaseModel):
    """
    CreateFlowEndpointInput
    """ # noqa: E501
    name: StrictStr = Field(description="The name of the ranking flow.")
    criteria: StrictStr = Field(description="The ranking criteria used to compare items.")
    validation_set_id: Optional[StrictStr] = Field(default=None, description="Optional ID of the validation set to use.", alias="validationSetId")
    starting_elo: Optional[StrictInt] = Field(default=None, description="Initial Elo rating for new items. Defaults to 1200.", alias="startingElo")
    k_factor: Optional[StrictInt] = Field(default=None, description="K-factor controlling Elo rating sensitivity. Defaults to 40.", alias="kFactor")
    scaling_factor: Optional[StrictInt] = Field(default=None, description="Scaling factor for Elo probability calculation. Defaults to 400.", alias="scalingFactor")
    max_responses: Optional[StrictInt] = Field(default=None, description="Maximum number of responses per comparison.", alias="maxResponses")
    serve_to_response_ratio: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Ratio of concurrent serves to max responses. When set, limits serving to avoid over-collection.", alias="serveToResponseRatio")
    serve_timeout_seconds: Optional[StrictInt] = Field(default=None, description="Time in seconds a user has to submit an answer after loading the task. When set, overrides the global default.", alias="serveTimeoutSeconds")
    min_responses: Optional[StrictInt] = Field(default=None, description="Minimum number of responses per comparison. Defaults to 1.", alias="minResponses")
    responses_required: Optional[StrictInt] = Field(default=None, description="Deprecated. Use MaxResponses instead.", alias="responsesRequired")
    feature_flags: Optional[List[FeatureFlag]] = Field(default=None, alias="featureFlags")
    __properties: ClassVar[List[str]] = ["name", "criteria", "validationSetId", "startingElo", "kFactor", "scalingFactor", "maxResponses", "serveToResponseRatio", "serveTimeoutSeconds", "minResponses", "responsesRequired", "featureFlags"]

    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 CreateFlowEndpointInput 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 feature_flags (list)
        _items = []
        if self.feature_flags:
            for _item_feature_flags in self.feature_flags:
                if _item_feature_flags:
                    _items.append(_item_feature_flags.to_dict())
            _dict['featureFlags'] = _items
        # set to None if validation_set_id (nullable) is None
        # and model_fields_set contains the field
        if self.validation_set_id is None and "validation_set_id" in self.model_fields_set:
            _dict['validationSetId'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of CreateFlowEndpointInput 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"),
            "criteria": obj.get("criteria"),
            "validationSetId": obj.get("validationSetId"),
            "startingElo": obj.get("startingElo"),
            "kFactor": obj.get("kFactor"),
            "scalingFactor": obj.get("scalingFactor"),
            "maxResponses": obj.get("maxResponses"),
            "serveToResponseRatio": obj.get("serveToResponseRatio"),
            "serveTimeoutSeconds": obj.get("serveTimeoutSeconds"),
            "minResponses": obj.get("minResponses"),
            "responsesRequired": obj.get("responsesRequired"),
            "featureFlags": [FeatureFlag.from_dict(_item) for _item in obj["featureFlags"]] if obj.get("featureFlags") is not None else None
        })
        return _obj


