# coding: utf-8

"""
    Ringer Business API - Items Management

    This API provides endpoints for managing individual billable items or features. Items represent the most granular level of service components (e.g., a specific calling feature, a per-minute rate for a call type, a monthly fee for a service). These items can be part of packages or plans.  Currently, this API focuses on allowing updates to items, typically related to their pricing within a specific price deck context. 

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

class ItemCore(BaseModel):
    """
    ItemCore
    """ # noqa: E501
    id: StrictInt = Field(description="Unique identifier for the item.")
    name: StrictStr = Field(description="The human-readable name of the item or feature.")
    item_type: StrictStr = Field(description="The general category or type of the item (e.g., cdr, service_fee, feature_license).")
    item_rules: Optional[StrictStr] = Field(default=None, description="Specific rules or sub-classification for the item type that might affect rating or behavior.")
    item_price: StrictStr = Field(description="The price of this individual item (e.g., per unit, per month).")
    currency: StrictStr = Field(description="Three-letter ISO currency code for the item price.")
    price_deck_id: Optional[StrictInt] = Field(default=None, description="Identifier of the price deck this item pricing might belong to.")
    tax_category: Optional[StrictInt] = Field(default=None, description="Identifier for the tax category applicable to this item.")
    tax_code: Optional[StrictInt] = Field(default=None, description="Specific tax code applicable to this item.")
    __properties: ClassVar[List[str]] = ["id", "name", "item_type", "item_rules", "item_price", "currency", "price_deck_id", "tax_category", "tax_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 ItemCore 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 item_rules (nullable) is None
        # and model_fields_set contains the field
        if self.item_rules is None and "item_rules" in self.model_fields_set:
            _dict['item_rules'] = None

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ItemCore 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"),
            "name": obj.get("name"),
            "item_type": obj.get("item_type"),
            "item_rules": obj.get("item_rules"),
            "item_price": obj.get("item_price"),
            "currency": obj.get("currency") if obj.get("currency") is not None else 'USD',
            "price_deck_id": obj.get("price_deck_id"),
            "tax_category": obj.get("tax_category"),
            "tax_code": obj.get("tax_code")
        })
        return _obj


