# coding: utf-8

"""
    Ringer Business API

    This API provides comprehensive endpoints for the Ringer Business system. It includes functionality for managing customer accounts, addresses, sites,  phone numbers, payments, users, and other business resources.  Operations typically require authentication and appropriate permissions. 

    The version of the OpenAPI document: 1.0.4
    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, SecretStr, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class SipTrunkCreateRequest(BaseModel):
    """
    Data required to create a new SIP Trunk.
    """ # noqa: E501
    name: StrictStr = Field(description="A user-friendly name for the SIP Trunk.")
    login: Optional[StrictStr] = Field(default=None, description="Username for SIP registration/authentication. Can be system-generated if omitted on create.")
    password: Optional[SecretStr] = Field(default=None, description="Password for SIP registration. System-generated if omitted on create. Not returned on GET.")
    active: Optional[StrictBool] = Field(default=True, description="Indicates if the SIP Trunk is active.")
    channel_limit: Optional[StrictInt] = Field(default=10, description="Maximum number of concurrent call channels allowed for this trunk.")
    contact_ip: Optional[StrictStr] = Field(default=None, description="Optional. IP address and port (e.g., 63.211.239.14:5060) to send inbound calls to, bypassing registration.")
    acl: Optional[StrictStr] = Field(default='0.0.0.0/0', description="Access Control List (IP address or range) restricting where this trunk can connect from/to.")
    caller_id_name: Optional[StrictStr] = Field(default=None, description="Default Caller ID name for outbound calls from this trunk.")
    caller_id_number: Optional[StrictStr] = Field(default=None, description="Default Caller ID number for outbound calls from this trunk.")
    disable_comfort_noise: Optional[StrictBool] = Field(default=False, description="Disable RFC3389 Comfort Noise if hardware does not support it.")
    timeout: Optional[StrictInt] = Field(default=120, description="Timeout in seconds for call attempts or registration.")
    fail_over_destination_code: Optional[StrictStr] = Field(default=None, description="System code for the failover destination if the trunk is unavailable.")
    user_id: Optional[StrictInt] = Field(default=None, description="Optional. Identifier of a user primarily associated with this SIP trunk.")
    __properties: ClassVar[List[str]] = ["name", "login", "password", "active", "channel_limit", "contact_ip", "acl", "caller_id_name", "caller_id_number", "disable_comfort_noise", "timeout", "fail_over_destination_code", "user_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 SipTrunkCreateRequest 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 password (nullable) is None
        # and model_fields_set contains the field
        if self.password is None and "password" in self.model_fields_set:
            _dict['password'] = None

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of SipTrunkCreateRequest 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"),
            "password": obj.get("password"),
            "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 10,
            "contact_ip": obj.get("contact_ip"),
            "acl": obj.get("acl") if obj.get("acl") is not None else '0.0.0.0/0',
            "caller_id_name": obj.get("caller_id_name"),
            "caller_id_number": obj.get("caller_id_number"),
            "disable_comfort_noise": obj.get("disable_comfort_noise") if obj.get("disable_comfort_noise") is not None else False,
            "timeout": obj.get("timeout") if obj.get("timeout") is not None else 120,
            "fail_over_destination_code": obj.get("fail_over_destination_code"),
            "user_id": obj.get("user_id")
        })
        return _obj


