# coding: utf-8

"""
    Ringer Business API - Call Blocking Management

    This API provides endpoints for managing call blocking rules on a specific site. Call blocking allows customers to prevent inbound calls from specified numbers to certain extensions or all extensions on a site. When a blocked number attempts to call, they will typically receive a busy tone.  Functionality includes: - Listing all call block rules for a site. - Creating a new call block rule. - Retrieving details of a specific call block rule. - Updating an existing call block rule. - Deleting a call block rule. 

    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 ringer_business.models.link import Link
from typing import Optional, Set
from typing_extensions import Self

class CallBlockResponse(BaseModel):
    """
    Detailed information about a call block rule.
    """ # noqa: E501
    number_to_block: StrictStr = Field(description="The phone number (or pattern) to block. E.164 format recommended for specific numbers.")
    block_all_extensions: StrictBool = Field(description="If true, calls from the number are blocked to all extensions on the site. If false, `applicable_extensions` must be specified.")
    applicable_extensions: Optional[List[StrictStr]] = Field(default=None, description="A list of specific extension identifiers (e.g., device codes, extension numbers) to which this block applies. Used if `block_all_extensions` is false.")
    notes: Optional[StrictStr] = Field(default=None, description="Optional notes or reason for this call block rule.")
    id: StrictInt = Field(description="Unique identifier for the call block rule.")
    site_id: StrictInt = Field(description="Identifier of the site this call block rule belongs to.")
    links: Optional[List[Link]] = Field(default=None, description="HATEOAS links related to this call block rule.")
    __properties: ClassVar[List[str]] = ["number_to_block", "block_all_extensions", "applicable_extensions", "notes", "id", "site_id", "links"]

    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 CallBlockResponse 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 links (list)
        _items = []
        if self.links:
            for _item_links in self.links:
                if _item_links:
                    _items.append(_item_links.to_dict())
            _dict['links'] = _items
        # set to None if applicable_extensions (nullable) is None
        # and model_fields_set contains the field
        if self.applicable_extensions is None and "applicable_extensions" in self.model_fields_set:
            _dict['applicable_extensions'] = None

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "number_to_block": obj.get("number_to_block"),
            "block_all_extensions": obj.get("block_all_extensions"),
            "applicable_extensions": obj.get("applicable_extensions"),
            "notes": obj.get("notes"),
            "id": obj.get("id"),
            "site_id": obj.get("site_id"),
            "links": [Link.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None
        })
        return _obj


