# 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, StrictStr, field_validator
from typing import Any, ClassVar, Dict, List, Optional
from typing import Optional, Set
from typing_extensions import Self

class StripeCustomerPortalRequest(BaseModel):
    """
    StripeCustomerPortalRequest
    """ # noqa: E501
    return_url: StrictStr = Field(description="URL to redirect to when the customer exits the portal (back button)")
    subscription_id: Optional[StrictStr] = Field(default=None, description="Subscription ID required for subscription_update or subscription_cancel flows")
    flow_type: Optional[StrictStr] = Field(default=None, description="Type of flow to present: 'payment_method_update' for adding/updating payment method, 'subscription_update' for updating subscription, 'subscription_cancel' for cancellation. If not provided, shows the default portal homepage.  * `payment_method_update` - Payment Method Update * `subscription_update` - Subscription Update * `subscription_cancel` - Subscription Cancel")
    after_completion_url: Optional[StrictStr] = Field(default=None, description="URL to redirect after the flow is completed successfully. Only used when flow_type is set. Defaults to return_url if not provided.")
    __properties: ClassVar[List[str]] = ["return_url", "subscription_id", "flow_type", "after_completion_url"]

    @field_validator('flow_type')
    def flow_type_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in set(['payment_method_update', 'subscription_update', 'subscription_cancel']):
            raise ValueError("must be one of enum values ('payment_method_update', 'subscription_update', 'subscription_cancel')")
        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 StripeCustomerPortalRequest 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,
        )
        # set to None if flow_type (nullable) is None
        # and model_fields_set contains the field
        if self.flow_type is None and "flow_type" in self.model_fields_set:
            _dict['flow_type'] = None

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

        return _dict

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

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

        _obj = cls.model_validate({
            "return_url": obj.get("return_url"),
            "subscription_id": obj.get("subscription_id"),
            "flow_type": obj.get("flow_type"),
            "after_completion_url": obj.get("after_completion_url")
        })
        return _obj


