# coding: utf-8

"""
    FlexPrice API

    FlexPrice API Service

    The version of the OpenAPI document: 1.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, Field, StrictStr
from typing import Any, ClassVar, Dict, List, Optional
from flexprice.models.dto_billing_cycle_info import DtoBillingCycleInfo
from flexprice.models.dto_invoice_preview import DtoInvoicePreview
from flexprice.models.dto_plan_summary import DtoPlanSummary
from flexprice.models.dto_proration_details import DtoProrationDetails
from flexprice.models.types_subscription_change_type import TypesSubscriptionChangeType
from typing import Optional, Set
from typing_extensions import Self

class DtoSubscriptionChangePreviewResponse(BaseModel):
    """
    Response showing the financial impact of a subscription plan change
    """ # noqa: E501
    change_type: Optional[TypesSubscriptionChangeType] = None
    current_plan: Optional[DtoPlanSummary] = None
    effective_date: Optional[StrictStr] = Field(default=None, description="effective_date is when the change would take effect")
    metadata: Optional[Dict[str, StrictStr]] = Field(default=None, description="metadata from the request")
    new_billing_cycle: Optional[DtoBillingCycleInfo] = None
    next_invoice_preview: Optional[DtoInvoicePreview] = None
    proration_details: Optional[DtoProrationDetails] = None
    subscription_id: Optional[StrictStr] = Field(default=None, description="subscription_id is the ID of the subscription being changed")
    target_plan: Optional[DtoPlanSummary] = None
    warnings: Optional[List[StrictStr]] = Field(default=None, description="warnings contains any warnings about the change")
    __properties: ClassVar[List[str]] = ["change_type", "current_plan", "effective_date", "metadata", "new_billing_cycle", "next_invoice_preview", "proration_details", "subscription_id", "target_plan", "warnings"]

    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 DtoSubscriptionChangePreviewResponse 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 current_plan
        if self.current_plan:
            _dict['current_plan'] = self.current_plan.to_dict()
        # override the default output from pydantic by calling `to_dict()` of new_billing_cycle
        if self.new_billing_cycle:
            _dict['new_billing_cycle'] = self.new_billing_cycle.to_dict()
        # override the default output from pydantic by calling `to_dict()` of next_invoice_preview
        if self.next_invoice_preview:
            _dict['next_invoice_preview'] = self.next_invoice_preview.to_dict()
        # override the default output from pydantic by calling `to_dict()` of proration_details
        if self.proration_details:
            _dict['proration_details'] = self.proration_details.to_dict()
        # override the default output from pydantic by calling `to_dict()` of target_plan
        if self.target_plan:
            _dict['target_plan'] = self.target_plan.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "change_type": obj.get("change_type"),
            "current_plan": DtoPlanSummary.from_dict(obj["current_plan"]) if obj.get("current_plan") is not None else None,
            "effective_date": obj.get("effective_date"),
            "metadata": obj.get("metadata"),
            "new_billing_cycle": DtoBillingCycleInfo.from_dict(obj["new_billing_cycle"]) if obj.get("new_billing_cycle") is not None else None,
            "next_invoice_preview": DtoInvoicePreview.from_dict(obj["next_invoice_preview"]) if obj.get("next_invoice_preview") is not None else None,
            "proration_details": DtoProrationDetails.from_dict(obj["proration_details"]) if obj.get("proration_details") is not None else None,
            "subscription_id": obj.get("subscription_id"),
            "target_plan": DtoPlanSummary.from_dict(obj["target_plan"]) if obj.get("target_plan") is not None else None,
            "warnings": obj.get("warnings")
        })
        return _obj


