# 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 pydantic import BaseModel, ConfigDict, Field, StrictBool, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from iblai.models.item_subscription import ItemSubscription
from iblai.models.item_type3e2_enum import ItemType3e2Enum
from typing import Optional, Set
from typing_extensions import Self

class ItemAccessCheckResponse(BaseModel):
    """
    Response for the generic item access check endpoint.  Mirrors :class:`PaymentCheckResult` but only exposes the fields relevant to API consumers.
    """ # noqa: E501
    has_access: StrictBool = Field(description="True if the user can access the item.")
    item_type: ItemType3e2Enum = Field(description="Item type that was checked (e.g. 'mentor').  * `mentor` - mentor * `course` - course * `program` - program * `pathway` - pathway")
    item_id: StrictStr = Field(description="ID of the item that was checked.")
    reason: StrictStr = Field(description="Machine-readable reason for the access decision (e.g. 'active', 'no_paywall', 'no_subscription').")
    requires_payment: StrictBool = Field(description="True if the user must pay to gain access.")
    pricing_available: StrictBool = Field(description="True if pricing tiers are available for purchase.")
    pricing: Optional[Any] = Field(default=None, description="Pricing details when access is denied (item name, tiers, amounts).")
    subscription: Optional[ItemSubscription] = Field(default=None, description="Active subscription details when the user has access via subscription.")
    __properties: ClassVar[List[str]] = ["has_access", "item_type", "item_id", "reason", "requires_payment", "pricing_available", "pricing", "subscription"]

    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 ItemAccessCheckResponse 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 subscription
        if self.subscription:
            _dict['subscription'] = self.subscription.to_dict()
        # set to None if pricing (nullable) is None
        # and model_fields_set contains the field
        if self.pricing is None and "pricing" in self.model_fields_set:
            _dict['pricing'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "has_access": obj.get("has_access"),
            "item_type": obj.get("item_type"),
            "item_id": obj.get("item_id"),
            "reason": obj.get("reason"),
            "requires_payment": obj.get("requires_payment"),
            "pricing_available": obj.get("pricing_available"),
            "pricing": obj.get("pricing"),
            "subscription": ItemSubscription.from_dict(obj["subscription"]) if obj.get("subscription") is not None else None
        })
        return _obj


