# 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, StrictFloat, StrictInt, StrictStr
from typing import Any, ClassVar, Dict, List, Optional, Union
from flexprice.models.dto_invoice_response import DtoInvoiceResponse
from flexprice.models.dto_proration_detail import DtoProrationDetail
from flexprice.models.types_cancellation_type import TypesCancellationType
from flexprice.models.types_subscription_status import TypesSubscriptionStatus
from typing import Optional, Set
from typing_extensions import Self

class DtoCancelSubscriptionResponse(BaseModel):
    """
    DtoCancelSubscriptionResponse
    """ # noqa: E501
    cancellation_type: Optional[TypesCancellationType] = None
    effective_date: Optional[StrictStr] = None
    message: Optional[StrictStr] = Field(default=None, description="Response metadata")
    processed_at: Optional[StrictStr] = None
    proration_details: Optional[List[DtoProrationDetail]] = None
    proration_invoice: Optional[DtoInvoiceResponse] = None
    reason: Optional[StrictStr] = None
    status: Optional[TypesSubscriptionStatus] = None
    subscription_id: Optional[StrictStr] = Field(default=None, description="Basic cancellation info")
    total_credit_amount: Optional[Union[StrictFloat, StrictInt]] = None
    __properties: ClassVar[List[str]] = ["cancellation_type", "effective_date", "message", "processed_at", "proration_details", "proration_invoice", "reason", "status", "subscription_id", "total_credit_amount"]

    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 DtoCancelSubscriptionResponse 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 each item in proration_details (list)
        _items = []
        if self.proration_details:
            for _item_proration_details in self.proration_details:
                if _item_proration_details:
                    _items.append(_item_proration_details.to_dict())
            _dict['proration_details'] = _items
        # override the default output from pydantic by calling `to_dict()` of proration_invoice
        if self.proration_invoice:
            _dict['proration_invoice'] = self.proration_invoice.to_dict()
        return _dict

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

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

        _obj = cls.model_validate({
            "cancellation_type": obj.get("cancellation_type"),
            "effective_date": obj.get("effective_date"),
            "message": obj.get("message"),
            "processed_at": obj.get("processed_at"),
            "proration_details": [DtoProrationDetail.from_dict(_item) for _item in obj["proration_details"]] if obj.get("proration_details") is not None else None,
            "proration_invoice": DtoInvoiceResponse.from_dict(obj["proration_invoice"]) if obj.get("proration_invoice") is not None else None,
            "reason": obj.get("reason"),
            "status": obj.get("status"),
            "subscription_id": obj.get("subscription_id"),
            "total_credit_amount": obj.get("total_credit_amount")
        })
        return _obj


