# coding: utf-8

"""
    Mixpeek API

    This is the Mixpeek API, providing access to various endpoints for data processing and retrieval.

    The version of the OpenAPI document: 1.3.0
    Contact: info@mixpeek.com
    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, Union
from typing_extensions import Annotated
from typing import Optional, Set
from typing_extensions import Self

class PredictorLift(BaseModel):
    """
    Lift calculation for a specific covariate value.  Lift measures how much a specific value increases/decreases conversion likelihood compared to the baseline. Lift > 1.0 means the value helps conversion.  Attributes:     field: Name of the covariate (e.g., \"Sender Domain\", \"Word Count Q3\")     value: Specific value or bin (e.g., \"gmail.com\", \"Q3\")     count: Number of sequences with this value     conversion_rate: Conversion rate for this value (0.0 to 1.0)     lift: Conversion rate / baseline rate (1.0 = no effect, >1.0 = positive, <1.0 = negative)  Example:     ```python     # Sender domain \"enterprise.com\" has 2.5x baseline conversion     PredictorLift(         field=\"Sender Domain\",         value=\"enterprise.com\",         count=150,         conversion_rate=0.75,  # 75% conversion         lift=2.5  # 2.5x the baseline rate     )     ```  Interpretation:     - lift = 1.5: This value increases conversion by 50%     - lift = 1.0: No effect on conversion     - lift = 0.5: This value decreases conversion by 50%
    """ # noqa: E501
    var_field: StrictStr = Field(description="Covariate field name", alias="field")
    value: StrictStr = Field(description="Specific value or bin label")
    count: Annotated[int, Field(strict=True, ge=0)] = Field(description="Number of sequences with this value")
    conversion_rate: Union[Annotated[float, Field(le=1.0, strict=True, ge=0.0)], Annotated[int, Field(le=1, strict=True, ge=0)]] = Field(description="Conversion rate for this value")
    lift: Union[StrictFloat, StrictInt] = Field(description="Lift relative to baseline (>1.0 = positive, <1.0 = negative)")
    __properties: ClassVar[List[str]] = ["field", "value", "count", "conversion_rate", "lift"]

    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 PredictorLift 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,
        )
        return _dict

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

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

        _obj = cls.model_validate({
            "field": obj.get("field"),
            "value": obj.get("value"),
            "count": obj.get("count"),
            "conversion_rate": obj.get("conversion_rate"),
            "lift": obj.get("lift")
        })
        return _obj


