# coding: utf-8

"""
    Ringer Business API - Plans Management

    This API provides endpoints for managing subscription plans associated with a customer account. It allows developers to: - List currently active plan(s) for an account. - List all plans available to an account. - Schedule a plan change for the next billing cycle. - Remove the current plan from an account. - Retrieve details of a specific plan. - Manage packages (add-ons) associated with a plan.  Plan management is crucial for defining the services and features available to a customer. 

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

class PlanResponse(BaseModel):
    """
    Detailed information about a subscription plan.
    """ # noqa: E501
    id: StrictInt
    name: StrictStr
    description: Optional[StrictStr] = None
    total_cost: StrictStr
    currency: StrictStr
    removable: StrictBool
    active: StrictBool
    approved: StrictBool
    finalized: StrictBool
    items: Optional[List[ItemResponse]] = Field(default=None, description="A list of individual billable items or features included or defined by this plan.")
    packages: Optional[PlanResponseAllOfPackages] = None
    links: Optional[List[Link]] = Field(default=None, description="HATEOAS links related to this plan.")
    __properties: ClassVar[List[str]] = ["id", "name", "description", "total_cost", "currency", "removable", "active", "approved", "finalized", "items", "packages", "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 PlanResponse 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 items (list)
        _items = []
        if self.items:
            for _item_items in self.items:
                if _item_items:
                    _items.append(_item_items.to_dict())
            _dict['items'] = _items
        # override the default output from pydantic by calling `to_dict()` of packages
        if self.packages:
            _dict['packages'] = self.packages.to_dict()
        # 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 description (nullable) is None
        # and model_fields_set contains the field
        if self.description is None and "description" in self.model_fields_set:
            _dict['description'] = None

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

        # set to None if packages (nullable) is None
        # and model_fields_set contains the field
        if self.packages is None and "packages" in self.model_fields_set:
            _dict['packages'] = 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 PlanResponse 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"),
            "description": obj.get("description"),
            "total_cost": obj.get("total_cost"),
            "currency": obj.get("currency") if obj.get("currency") is not None else 'USD',
            "removable": obj.get("removable"),
            "active": obj.get("active"),
            "approved": obj.get("approved"),
            "finalized": obj.get("finalized"),
            "items": [ItemResponse.from_dict(_item) for _item in obj["items"]] if obj.get("items") is not None else None,
            "packages": PlanResponseAllOfPackages.from_dict(obj["packages"]) if obj.get("packages") is not None else None,
            "links": [Link.from_dict(_item) for _item in obj["links"]] if obj.get("links") is not None else None
        })
        return _obj


