# coding: utf-8

"""
    Ringer Business Common Components

    A collection of common reusable OpenAPI components for the Ringer Business API.

    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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class DeviceCore(BaseModel):
    """
    Core properties of a device, used for creation and as part of responses.
    """ # noqa: E501
    name: StrictStr = Field(description="A user-friendly name for the device.")
    login: StrictStr = Field(description="SIP username for the device.")
    active: Optional[StrictBool] = Field(default=True, description="Whether the device is active.")
    channel_limit: Optional[StrictInt] = Field(default=2, description="Maximum concurrent calls for this device.")
    timeout: Optional[StrictInt] = Field(default=120, description="Ring timeout in seconds.")
    caller_id_name: Optional[StrictStr] = Field(default=None, description="Caller ID name to present for outbound calls from this device.")
    caller_id_number: Optional[StrictStr] = Field(default=None, description="Caller ID number (E.164) to present for outbound calls.")
    acl: Optional[StrictStr] = Field(default='0.0.0.0/0', description="Access Control List (IP/CIDR) for device registration.")
    fail_over_destination_code: Optional[StrictStr] = Field(default=None, description="System code for the destination if the device is unreachable or times out.")
    __properties: ClassVar[List[str]] = ["name", "login", "active", "channel_limit", "timeout", "caller_id_name", "caller_id_number", "acl", "fail_over_destination_code"]

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of DeviceCore 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"),
            "login": obj.get("login"),
            "active": obj.get("active") if obj.get("active") is not None else True,
            "channel_limit": obj.get("channel_limit") if obj.get("channel_limit") is not None else 2,
            "timeout": obj.get("timeout") if obj.get("timeout") is not None else 120,
            "caller_id_name": obj.get("caller_id_name"),
            "caller_id_number": obj.get("caller_id_number"),
            "acl": obj.get("acl") if obj.get("acl") is not None else '0.0.0.0/0',
            "fail_over_destination_code": obj.get("fail_over_destination_code")
        })
        return _obj


