# 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, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Union
from typing_extensions import Annotated
from mixpeek.models.transition_path import TransitionPath
from typing import Optional, Set
from typing_extensions import Self

class PathAnalysisResponse(BaseModel):
    """
    API response model for multi-step path analysis.  Contains discovered transition paths with frequency and duration statistics.  Example Response:     ```json     {         \"from_step\": \"inquiry\",         \"to_step\": \"closed_won\",         \"total_sequences\": 1000,         \"completed_sequences\": 350,         \"completion_rate\": 0.35,         \"paths\": [             {                 \"path\": [\"inquiry\", \"followup\", \"proposal\", \"closed_won\"],                 \"count\": 120,                 \"percentage\": 34.3,                 \"avg_duration_sec\": 604800.0             },             {                 \"path\": [\"inquiry\", \"proposal\", \"closed_won\"],                 \"count\": 90,                 \"percentage\": 25.7,                 \"avg_duration_sec\": 432000.0             },             {                 \"path\": [\"inquiry\", \"closed_won\"],                 \"count\": 70,                 \"percentage\": 20.0,                 \"avg_duration_sec\": 172800.0             }         ]     }     ```
    """ # noqa: E501
    from_step: StrictStr
    to_step: StrictStr
    total_sequences: StrictInt = Field(description="Total sequences that started at from_step")
    completed_sequences: StrictInt = Field(description="Number of sequences that reached to_step")
    completion_rate: Union[Annotated[float, Field(le=1.0, strict=True, ge=0.0)], Annotated[int, Field(le=1, strict=True, ge=0)]] = Field(description="Percentage that completed the path")
    paths: Annotated[List[TransitionPath], Field(max_length=100)] = Field(description="List of paths sorted by frequency (most common first)")
    __properties: ClassVar[List[str]] = ["from_step", "to_step", "total_sequences", "completed_sequences", "completion_rate", "paths"]

    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 PathAnalysisResponse 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 paths (list)
        _items = []
        if self.paths:
            for _item_paths in self.paths:
                if _item_paths:
                    _items.append(_item_paths.to_dict())
            _dict['paths'] = _items
        return _dict

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

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

        _obj = cls.model_validate({
            "from_step": obj.get("from_step"),
            "to_step": obj.get("to_step"),
            "total_sequences": obj.get("total_sequences"),
            "completed_sequences": obj.get("completed_sequences"),
            "completion_rate": obj.get("completion_rate"),
            "paths": [TransitionPath.from_dict(_item) for _item in obj["paths"]] if obj.get("paths") is not None else None
        })
        return _obj


