# coding: utf-8

"""
    FastAPI

    No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)

    The version of the OpenAPI document: 0.1.0
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from voiceos.models.agent_response import AgentResponse
from voiceos.models.call_cost import CallCost
from voiceos.models.call_status import CallStatus
from voiceos.models.call_type import CallType
from voiceos.models.ended_reasons import EndedReasons
from voiceos.models.message import Message
from typing import Optional, Set
from typing_extensions import Self

class CallResponse(BaseModel):
    """
    CallResponse
    """ # noqa: E501
    uri: StrictStr = Field(description="The uri of the conversation.")
    type: CallType = Field(description="The type of the call.")
    status: CallStatus = Field(description="The status of the conversation (live or ended).")
    to_number: Optional[StrictStr] = Field(default=None, description="The phone number that the call is going to.")
    from_number: Optional[StrictStr] = Field(default=None, description="The phone number that call is coming from.")
    start_time: datetime = Field(description="The start time of the conversation.")
    end_time: Optional[datetime] = Field(default=None, description="The end time of the conversation.")
    agent: AgentResponse = Field(description="The agent used for the call.")
    agent_id: Optional[StrictStr] = Field(default=None, description="The id of the agent used in the call. Returns null if the call did not use an existing agent.")
    messages: Optional[List[Message]] = Field(default=None, description="The messages of the conversation.")
    account_id: StrictStr = Field(description="The account id associated with of the conversation.")
    ended_reason: Optional[EndedReasons] = Field(default=None, description="The reasons the conversation ended.")
    cost: Optional[CallCost] = Field(default=None, description="The cost of the conversation.")
    id: StrictStr = Field(description="The id of the conversation.")
    __properties: ClassVar[List[str]] = ["uri", "type", "status", "to_number", "from_number", "start_time", "end_time", "agent", "agent_id", "messages", "account_id", "ended_reason", "cost", "id"]

    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 CallResponse 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 agent
        if self.agent:
            _dict['agent'] = self.agent.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in messages (list)
        _items = []
        if self.messages:
            for _item in self.messages:
                if _item:
                    _items.append(_item.to_dict())
            _dict['messages'] = _items
        # override the default output from pydantic by calling `to_dict()` of cost
        if self.cost:
            _dict['cost'] = self.cost.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "uri": obj.get("uri"),
            "type": obj.get("type"),
            "status": obj.get("status"),
            "to_number": obj.get("to_number"),
            "from_number": obj.get("from_number"),
            "start_time": obj.get("start_time"),
            "end_time": obj.get("end_time"),
            "agent": AgentResponse.from_dict(obj["agent"]) if obj.get("agent") is not None else None,
            "agent_id": obj.get("agent_id"),
            "messages": [Message.from_dict(_item) for _item in obj["messages"]] if obj.get("messages") is not None else None,
            "account_id": obj.get("account_id"),
            "ended_reason": obj.get("ended_reason"),
            "cost": CallCost.from_dict(obj["cost"]) if obj.get("cost") is not None else None,
            "id": obj.get("id")
        })
        return _obj


