# 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.existing_asset_input import ExistingAssetInput
from rapidata.api_client.models.i_audience_filter import IAudienceFilter
from typing import Optional, Set
from typing_extensions import Self

class UpdateAudienceRequest(BaseModel):
    """
    The body request to update an audience.
    """ # noqa: E501
    name: Optional[StrictStr] = Field(default=None, description="The new name to give to this audience.")
    description: Optional[StrictStr] = Field(default=None, description="The new description for the audience. Supports markdown. Set to null to remove.")
    filters: Optional[List[IAudienceFilter]] = None
    logo: Optional[ExistingAssetInput] = None
    min_graduated_for_distilling_boost: Optional[StrictInt] = Field(default=None, description="Minimum graduated users before disabling distilling boost.  When graduated count is below this, external distilling audience ID is added to campaign boosting.", alias="minGraduatedForDistillingBoost")
    min_distilling_for_global_boost: Optional[StrictInt] = Field(default=None, description="Minimum distilling users before disabling global boost.  When distilling count is below this, GlobalBoostLevel is set above zero.", alias="minDistillingForGlobalBoost")
    minimum_user_score: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="The minimum user score used to determine whether a user can be included in an audience.", alias="minimumUserScore")
    max_distilling_responses: Optional[StrictInt] = Field(default=None, description="Maximum responses before user exits the distilling campaign.  Set to null to disable this exit condition.", alias="maxDistillingResponses")
    min_distilling_responses: Optional[StrictInt] = Field(default=None, description="Minimum responses before the score floor check applies.  Users need at least this many responses before they can be kicked out for low score.  Set to null to apply score floor check from the first response.", alias="minDistillingResponses")
    min_distilling_score_floor: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Minimum user score floor - users below this score exit the distilling campaign  (only after completing MinDistillingResponses).  Set to null to disable this exit condition.", alias="minDistillingScoreFloor")
    max_distilling_sessions: Optional[StrictInt] = Field(default=None, description="Maximum sessions (rapid retrievals) before user exits the distilling campaign.  Set to a value to enable session-based exit condition.", alias="maxDistillingSessions")
    inactivity_drop_days: Optional[StrictInt] = Field(default=None, description="Number of days of inactivity before a distilling user is dropped.  Set to null to disable this exit condition.", alias="inactivityDropDays")
    min_submission_rate: Optional[Union[StrictFloat, StrictInt]] = Field(default=None, description="Minimum submission rate (responses / sessions) before a user is dropped.  Set to null to disable this exit condition.", alias="minSubmissionRate")
    min_sessions_for_submission_rate: Optional[StrictInt] = Field(default=None, description="Minimum number of sessions before the submission rate check applies.  Set to null to apply from the first session.", alias="minSessionsForSubmissionRate")
    distilling_retrieval_mode: Optional[StrictStr] = Field(default=None, description="The retrieval mode used by the distilling campaign to select rapids for users.", alias="distillingRetrievalMode")
    __properties: ClassVar[List[str]] = ["name", "description", "filters", "logo", "minGraduatedForDistillingBoost", "minDistillingForGlobalBoost", "minimumUserScore", "maxDistillingResponses", "minDistillingResponses", "minDistillingScoreFloor", "maxDistillingSessions", "inactivityDropDays", "minSubmissionRate", "minSessionsForSubmissionRate", "distillingRetrievalMode"]

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

        if value not in set(['Random', 'Shuffled', 'Sequential']):
            raise ValueError("must be one of enum values ('Random', 'Shuffled', 'Sequential')")
        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 UpdateAudienceRequest 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 filters (list)
        _items = []
        if self.filters:
            for _item_filters in self.filters:
                if _item_filters:
                    _items.append(_item_filters.to_dict())
            _dict['filters'] = _items
        # override the default output from pydantic by calling `to_dict()` of logo
        if self.logo:
            _dict['logo'] = self.logo.to_dict()
        # set to None if name (nullable) is None
        # and model_fields_set contains the field
        if self.name is None and "name" in self.model_fields_set:
            _dict['name'] = None

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

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

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

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

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

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of UpdateAudienceRequest 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"),
            "description": obj.get("description"),
            "filters": [IAudienceFilter.from_dict(_item) for _item in obj["filters"]] if obj.get("filters") is not None else None,
            "logo": ExistingAssetInput.from_dict(obj["logo"]) if obj.get("logo") is not None else None,
            "minGraduatedForDistillingBoost": obj.get("minGraduatedForDistillingBoost"),
            "minDistillingForGlobalBoost": obj.get("minDistillingForGlobalBoost"),
            "minimumUserScore": obj.get("minimumUserScore"),
            "maxDistillingResponses": obj.get("maxDistillingResponses"),
            "minDistillingResponses": obj.get("minDistillingResponses"),
            "minDistillingScoreFloor": obj.get("minDistillingScoreFloor"),
            "maxDistillingSessions": obj.get("maxDistillingSessions"),
            "inactivityDropDays": obj.get("inactivityDropDays"),
            "minSubmissionRate": obj.get("minSubmissionRate"),
            "minSessionsForSubmissionRate": obj.get("minSessionsForSubmissionRate"),
            "distillingRetrievalMode": obj.get("distillingRetrievalMode")
        })
        return _obj


