# coding: utf-8

"""
    Ringer Business API - Call Records

    This API provides an endpoint for retrieving Call Detail Records (CDRs). Call records offer detailed information about calls made or received through the Ringer Business system, including source, destination, duration, cost, and timestamps.  Access to call records can be filtered by time range, paginated, sorted, and filtered by various call attributes. Permissions might vary; administrators may see all records for an organization, while individual users might only see their own. 

    The version of the OpenAPI document: 1.0.0
    Contact: support@ringer.tel
    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, StrictInt, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class CallRecordItemSummary(BaseModel):
    """
    Summary details of a specific call event.
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for this call summary record.")
    dni: StrictStr = Field(description="Dialed Number Identifier (DNIS).")
    dni_name: Optional[StrictStr] = Field(default=None, description="Name associated with the DNI (e.g., location or service).")
    raw_ani: StrictStr = Field(description="Automatic Number Identification (ANI) of the caller.")
    name: Optional[StrictStr] = Field(default=None, description="A descriptive name for the call type or leg.")
    zone: Optional[StrictStr] = Field(default=None, description="Dialing zone or rate category for the call.")
    direction: StrictStr
    start_stamp: datetime
    answer_stamp: Optional[datetime] = None
    end_stamp: Optional[datetime] = None
    duration: Optional[StrictInt] = Field(default=None, description="Duration of the answered part of the call in seconds.")
    __properties: ClassVar[List[str]] = ["id", "dni", "dni_name", "raw_ani", "name", "zone", "direction", "start_stamp", "answer_stamp", "end_stamp", "duration"]

    @field_validator('direction')
    def direction_validate_enum(cls, value):
        """Validates the enum"""
        if value not in set(['inbound', 'outbound']):
            raise ValueError("must be one of enum values ('inbound', 'outbound')")
        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 CallRecordItemSummary 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,
        )
        # set to None if dni_name (nullable) is None
        # and model_fields_set contains the field
        if self.dni_name is None and "dni_name" in self.model_fields_set:
            _dict['dni_name'] = None

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "id": obj.get("id"),
            "dni": obj.get("dni"),
            "dni_name": obj.get("dni_name"),
            "raw_ani": obj.get("raw_ani"),
            "name": obj.get("name"),
            "zone": obj.get("zone"),
            "direction": obj.get("direction"),
            "start_stamp": obj.get("start_stamp"),
            "answer_stamp": obj.get("answer_stamp"),
            "end_stamp": obj.get("end_stamp"),
            "duration": obj.get("duration")
        })
        return _obj


