# coding: utf-8

"""
    bxb API

    A comprehensive usage-based billing platform API. Manage customers, plans, subscriptions, invoices, payments, wallets, coupons, credit notes, taxes, webhooks, and more.

    The version of the OpenAPI document: 0.5.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 datetime import datetime
from pydantic import BaseModel, ConfigDict, StrictBool, StrictInt
from typing import Any, ClassVar, Dict, List, Optional
from uuid import UUID
from bxb.models.billing_time import BillingTime
from bxb.models.subscription_status import SubscriptionStatus
from bxb.models.termination_action import TerminationAction
from typing import Optional, Set
from typing_extensions import Self

class SubscriptionUpdate(BaseModel):
    """
    SubscriptionUpdate
    """ # noqa: E501
    plan_id: Optional[UUID] = None
    status: Optional[SubscriptionStatus] = None
    ending_at: Optional[datetime] = None
    canceled_at: Optional[datetime] = None
    billing_time: Optional[BillingTime] = None
    trial_period_days: Optional[StrictInt] = None
    trial_ended_at: Optional[datetime] = None
    subscription_at: Optional[datetime] = None
    pay_in_advance: Optional[StrictBool] = None
    previous_plan_id: Optional[UUID] = None
    downgraded_at: Optional[datetime] = None
    on_termination_action: Optional[TerminationAction] = None
    __properties: ClassVar[List[str]] = ["plan_id", "status", "ending_at", "canceled_at", "billing_time", "trial_period_days", "trial_ended_at", "subscription_at", "pay_in_advance", "previous_plan_id", "downgraded_at", "on_termination_action"]

    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 SubscriptionUpdate 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 plan_id (nullable) is None
        # and model_fields_set contains the field
        if self.plan_id is None and "plan_id" in self.model_fields_set:
            _dict['plan_id'] = None

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

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

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

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

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

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

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

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

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

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

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

        return _dict

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

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

        _obj = cls.model_validate({
            "plan_id": obj.get("plan_id"),
            "status": obj.get("status"),
            "ending_at": obj.get("ending_at"),
            "canceled_at": obj.get("canceled_at"),
            "billing_time": obj.get("billing_time"),
            "trial_period_days": obj.get("trial_period_days"),
            "trial_ended_at": obj.get("trial_ended_at"),
            "subscription_at": obj.get("subscription_at"),
            "pay_in_advance": obj.get("pay_in_advance"),
            "previous_plan_id": obj.get("previous_plan_id"),
            "downgraded_at": obj.get("downgraded_at"),
            "on_termination_action": obj.get("on_termination_action")
        })
        return _obj


