# 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, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing_extensions import Annotated
from uuid import UUID
from iblai.models.interval_enum import IntervalEnum
from typing import Optional, Set
from typing_extensions import Self

class ItemPrice(BaseModel):
    """
    ItemPrice
    """ # noqa: E501
    id: UUID
    name: Annotated[str, Field(strict=True, max_length=255)] = Field(description="Display name for this pricing tier (e.g., 'Basic', 'Premium')")
    description: Optional[StrictStr] = Field(default=None, description="Description of what's included in this tier")
    amount: Annotated[str, Field(strict=True)] = Field(description="Price amount in USD (e.g., 9.99 for $9.99, 0 for free)")
    currency: Optional[Annotated[str, Field(strict=True, max_length=3)]] = Field(default=None, description="Currency code (e.g., 'usd', 'eur')")
    interval: Optional[IntervalEnum] = Field(default=None, description="Billing interval  * `month` - Monthly * `year` - Yearly * `one_time` - One Time")
    stripe_price_id: Optional[StrictStr] = Field(description="Stripe Price ID (on the connected account)")
    is_active: Optional[StrictBool] = Field(default=None, description="Whether this price is currently available for purchase")
    features: Optional[Any] = Field(default=None, description="List of features included in this tier")
    sort_order: Optional[StrictInt] = Field(default=None, description="Display order for this price tier")
    created_at: datetime
    updated_at: datetime
    __properties: ClassVar[List[str]] = ["id", "name", "description", "amount", "currency", "interval", "stripe_price_id", "is_active", "features", "sort_order", "created_at", "updated_at"]

    @field_validator('amount')
    def amount_validate_regular_expression(cls, value):
        """Validates the regular expression"""
        if not re.match(r"^-?\d{0,8}(?:\.\d{0,2})?$", value):
            raise ValueError(r"must validate the regular expression /^-?\d{0,8}(?:\.\d{0,2})?$/")
        return value

    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 ItemPrice 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.
        """
        excluded_fields: Set[str] = set([
            "id",
            "stripe_price_id",
            "created_at",
            "updated_at",
        ])

        _dict = self.model_dump(
            by_alias=True,
            exclude=excluded_fields,
            exclude_none=True,
        )
        # 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 stripe_price_id (nullable) is None
        # and model_fields_set contains the field
        if self.stripe_price_id is None and "stripe_price_id" in self.model_fields_set:
            _dict['stripe_price_id'] = None

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

        return _dict

    @classmethod
    def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
        """Create an instance of ItemPrice 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"),
            "amount": obj.get("amount"),
            "currency": obj.get("currency"),
            "interval": obj.get("interval"),
            "stripe_price_id": obj.get("stripe_price_id"),
            "is_active": obj.get("is_active"),
            "features": obj.get("features"),
            "sort_order": obj.get("sort_order"),
            "created_at": obj.get("created_at"),
            "updated_at": obj.get("updated_at")
        })
        return _obj


