# coding: utf-8

"""
    FlowHunt

    FlowHunt API

    The version of the OpenAPI document: 2.0.0
    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, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from flowhunt.models.feature_response import FeatureResponse
from flowhunt.models.subscription_plan import SubscriptionPlan
from typing import Optional, Set
from typing_extensions import Self

class PlanListItemResponse(BaseModel):
    """
    PlanListItemResponse
    """ # noqa: E501
    product_id: StrictStr
    price_id: StrictStr
    currency: StrictStr
    amount_monthly: StrictInt
    amount_yearly: Optional[StrictInt] = None
    recurring: StrictBool
    name: StrictStr
    description: StrictStr
    popular: StrictBool
    monthly_credits: StrictInt
    features: List[FeatureResponse]
    subscription_plan: Optional[SubscriptionPlan]
    self_hosted: Optional[StrictBool] = None
    addon: Optional[StrictBool] = None
    addon_type: Optional[StrictStr] = None
    __properties: ClassVar[List[str]] = ["product_id", "price_id", "currency", "amount_monthly", "amount_yearly", "recurring", "name", "description", "popular", "monthly_credits", "features", "subscription_plan", "self_hosted", "addon", "addon_type"]

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "product_id": obj.get("product_id"),
            "price_id": obj.get("price_id"),
            "currency": obj.get("currency"),
            "amount_monthly": obj.get("amount_monthly"),
            "amount_yearly": obj.get("amount_yearly"),
            "recurring": obj.get("recurring"),
            "name": obj.get("name"),
            "description": obj.get("description"),
            "popular": obj.get("popular"),
            "monthly_credits": obj.get("monthly_credits"),
            "features": [FeatureResponse.from_dict(_item) for _item in obj["features"]] if obj.get("features") is not None else None,
            "subscription_plan": obj.get("subscription_plan"),
            "self_hosted": obj.get("self_hosted"),
            "addon": obj.get("addon"),
            "addon_type": obj.get("addon_type")
        })
        return _obj


