# 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, field_validator
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 UpdateConfigEndpointInput(BaseModel):
    """
    UpdateConfigEndpointInput
    """ # noqa: E501
    criteria: Optional[StrictStr] = Field(default=None, description="The ranking criteria used to compare items.")
    starting_elo: Optional[StrictInt] = Field(default=None, description="Initial Elo rating for new items.", alias="startingElo")
    k_factor: Optional[StrictInt] = Field(default=None, description="K-factor controlling Elo rating sensitivity.", alias="kFactor")
    scaling_factor: Optional[StrictInt] = Field(default=None, description="Scaling factor for Elo probability calculation.", alias="scalingFactor")
    min_responses: Optional[StrictInt] = Field(default=None, description="Minimum number of responses per comparison.", alias="minResponses")
    max_responses: Optional[StrictInt] = Field(default=None, description="Maximum number of responses per comparison.", alias="maxResponses")
    responses_required: Optional[StrictInt] = Field(default=None, description="Deprecated. Use MaxResponses instead.", alias="responsesRequired")
    feature_flags: Optional[List[FeatureFlag]] = Field(default=None, alias="featureFlags")
    target_response_count: Optional[StrictInt] = Field(default=None, description="Target average response count per completed item. Set to null to disable PID control.", alias="targetResponseCount")
    pid_proportional_gain: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="PID proportional gain.", alias="pidProportionalGain")
    pid_integral_gain: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="PID integral gain.", alias="pidIntegralGain")
    pid_derivative_gain: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="PID derivative gain.", alias="pidDerivativeGain")
    pid_min_sessions_per_minute: Optional[StrictInt] = Field(default=None, description="Minimum sessions per minute the PID can set.", alias="pidMinSessionsPerMinute")
    pid_max_sessions_per_minute: Optional[StrictInt] = Field(default=None, description="Maximum sessions per minute the PID can set.", alias="pidMaxSessionsPerMinute")
    pid_batch_mode: Optional[StrictStr] = Field(default=None, description="How PID output maps to campaign rate. Total: direct rate. PerBatch: multiplied by active batch count. PerBatchTimeWeighted: multiplied by time-weighted batch count.", alias="pidBatchMode")
    __properties: ClassVar[List[str]] = ["criteria", "startingElo", "kFactor", "scalingFactor", "minResponses", "maxResponses", "responsesRequired", "featureFlags", "targetResponseCount", "pidProportionalGain", "pidIntegralGain", "pidDerivativeGain", "pidMinSessionsPerMinute", "pidMaxSessionsPerMinute", "pidBatchMode"]

    @field_validator('pid_batch_mode')
    def pid_batch_mode_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['Total', 'PerBatch', 'PerBatchTimeWeighted']):
            raise ValueError("must be one of enum values ('Total', 'PerBatch', 'PerBatchTimeWeighted')")
        return value

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "criteria": obj.get("criteria"),
            "startingElo": obj.get("startingElo"),
            "kFactor": obj.get("kFactor"),
            "scalingFactor": obj.get("scalingFactor"),
            "minResponses": obj.get("minResponses"),
            "maxResponses": obj.get("maxResponses"),
            "responsesRequired": obj.get("responsesRequired"),
            "featureFlags": [FeatureFlag.from_dict(_item) for _item in obj["featureFlags"]] if obj.get("featureFlags") is not None else None,
            "targetResponseCount": obj.get("targetResponseCount"),
            "pidProportionalGain": obj.get("pidProportionalGain"),
            "pidIntegralGain": obj.get("pidIntegralGain"),
            "pidDerivativeGain": obj.get("pidDerivativeGain"),
            "pidMinSessionsPerMinute": obj.get("pidMinSessionsPerMinute"),
            "pidMaxSessionsPerMinute": obj.get("pidMaxSessionsPerMinute"),
            "pidBatchMode": obj.get("pidBatchMode")
        })
        return _obj


