# coding: utf-8

"""
    ibl-data-manager

    API for iblai

    The version of the OpenAPI document: 4.202.1-ai-plus
    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 datetime import datetime
from pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from iblai.models.grandfathering_strategy_enum import GrandfatheringStrategyEnum
from iblai.models.item_price import ItemPrice
from iblai.models.item_type40f_enum import ItemType40fEnum
from typing import Optional, Set
from typing_extensions import Self

class ItemPaywallConfig(BaseModel):
    """
    ItemPaywallConfig
    """ # noqa: E501
    item_type: ItemType40fEnum = Field(description="Type of item being paywalled (e.g. mentor, course, program)  * `mentor` - Mentor * `course` - Course * `program` - Program * `pathway` - Pathway")
    item_id: Annotated[str, Field(strict=True, max_length=255)] = Field(description="Identifier for the item (UUID for mentors, slug/key for others)")
    item_name: StrictStr
    is_enabled: Optional[StrictBool] = Field(default=None, description="Whether the paywall is enabled for this item")
    description: Optional[StrictStr] = Field(default=None, description="Marketing description shown to customers at checkout. If blank, a default is generated from the item name.")
    allow_free_tier: Optional[StrictBool] = Field(default=None, description="Whether to allow a free tier (bypasses checkout)")
    stripe_product_id: Optional[StrictStr] = Field(description="Stripe Product ID for this item (on the connected account)")
    trial_period_days: Optional[StrictInt] = Field(default=None, description="Number of days for free trial (0 = no trial)")
    grandfathering_strategy: Optional[GrandfatheringStrategyEnum] = Field(default=None, description="How to handle existing users when enabling the paywall  * `free_forever` - Free Forever - Existing users get unlimited free access * `require_subscription` - Require Subscription - All users must subscribe (no grandfathering)")
    paywall_enabled_at: Optional[datetime] = Field(description="When the paywall was first enabled (for grandfathering cutoff)")
    prices: List[ItemPrice]
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["item_type", "item_id", "item_name", "is_enabled", "description", "allow_free_tier", "stripe_product_id", "trial_period_days", "grandfathering_strategy", "paywall_enabled_at", "prices", "created_at", "updated_at"]

    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 ItemPaywallConfig 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.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        * OpenAPI `readOnly` fields are excluded.
        """
        excluded_fields: Set[str] = set([
            "item_name",
            "stripe_product_id",
            "paywall_enabled_at",
            "prices",
            "created_at",
            "updated_at",
        ])

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "item_type": obj.get("item_type"),
            "item_id": obj.get("item_id"),
            "item_name": obj.get("item_name"),
            "is_enabled": obj.get("is_enabled"),
            "description": obj.get("description"),
            "allow_free_tier": obj.get("allow_free_tier"),
            "stripe_product_id": obj.get("stripe_product_id"),
            "trial_period_days": obj.get("trial_period_days"),
            "grandfathering_strategy": obj.get("grandfathering_strategy"),
            "paywall_enabled_at": obj.get("paywall_enabled_at"),
            "prices": [ItemPrice.from_dict(_item) for _item in obj["prices"]] if obj.get("prices") is not None else None,
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


