# coding: utf-8

"""
    Gigs Core API

    API to manage voice & data plans for smartphones, wearables and IoT in 200+ countries.  # noqa: E501

    The version of the OpenAPI document: 0.0.1
    Contact: support@gigs.com
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


from __future__ import annotations
import pprint
import re  # noqa: F401
import json


from typing import Any, Optional
from pydantic import BaseModel, Field, validator
from gigs_client.models.subscription_addon_addon import SubscriptionAddonAddon
from gigs_client.models.subscription_addon_current_period import SubscriptionAddonCurrentPeriod

class SubscriptionAddon(BaseModel):
    """
    <!-- theme: info --> > #### Preview > > This schema is currently in preview and might change in the future. > We’re excited to hear your feedback and ideas. Please send an email > to [support@gigs.com](mailto:support@gigs.com) to share your thoughts. 
    """
    object: Optional[Any] = Field(..., description="Type of object is always `subscriptionAddon`.")
    id: Optional[Any] = Field(..., description="Unique identifier for the subscription addon.")
    addon: SubscriptionAddonAddon = Field(...)
    current_period: SubscriptionAddonCurrentPeriod = Field(..., alias="currentPeriod")
    status: Optional[Any] = Field(..., description="The current status of the subscription addon.")
    subscription: Optional[Any] = Field(..., description="Unique identifier of the subscription the addon applies to.")
    user: Optional[Any] = Field(..., description="Unique identifier of the user the subscription addon belongs to.")
    activated_at: Optional[Any] = Field(..., alias="activatedAt", description="Time when the subscription addon was activated.")
    canceled_at: Optional[Any] = Field(..., alias="canceledAt", description="Time when the subscription addon was canceled.")
    created_at: Optional[Any] = Field(..., alias="createdAt", description="Time when the subscription addon was created.")
    ended_at: Optional[Any] = Field(..., alias="endedAt", description="Time when the subscription addon was ended.")
    __properties = ["object", "id", "addon", "currentPeriod", "status", "subscription", "user", "activatedAt", "canceledAt", "createdAt", "endedAt"]

    @validator('status')
    def status_validate_enum(cls, value):
        """Validates the enum"""
        if value is None:
            return value

        if value not in ('pending', 'active', 'ended'):
            raise ValueError("must be one of enum values ('pending', 'active', 'ended')")
        return value

    class Config:
        """Pydantic configuration"""
        allow_population_by_field_name = True
        validate_assignment = True

    def to_str(self) -> str:
        """Returns the string representation of the model using alias"""
        return pprint.pformat(self.dict(by_alias=True))

    def to_json(self) -> str:
        """Returns the JSON representation of the model using alias"""
        return json.dumps(self.to_dict())

    @classmethod
    def from_json(cls, json_str: str) -> SubscriptionAddon:
        """Create an instance of SubscriptionAddon from a JSON string"""
        return cls.from_dict(json.loads(json_str))

    def to_dict(self):
        """Returns the dictionary representation of the model using alias"""
        _dict = self.dict(by_alias=True,
                          exclude={
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of addon
        if self.addon:
            _dict['addon'] = self.addon.to_dict()
        # override the default output from pydantic by calling `to_dict()` of current_period
        if self.current_period:
            _dict['currentPeriod'] = self.current_period.to_dict()
        # set to None if object (nullable) is None
        # and __fields_set__ contains the field
        if self.object is None and "object" in self.__fields_set__:
            _dict['object'] = None

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

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

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

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

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

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

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

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

        return _dict

    @classmethod
    def from_dict(cls, obj: dict) -> SubscriptionAddon:
        """Create an instance of SubscriptionAddon from a dict"""
        if obj is None:
            return None

        if not isinstance(obj, dict):
            return SubscriptionAddon.parse_obj(obj)

        _obj = SubscriptionAddon.parse_obj({
            "object": obj.get("object"),
            "id": obj.get("id"),
            "addon": SubscriptionAddonAddon.from_dict(obj.get("addon")) if obj.get("addon") is not None else None,
            "current_period": SubscriptionAddonCurrentPeriod.from_dict(obj.get("currentPeriod")) if obj.get("currentPeriod") is not None else None,
            "status": obj.get("status"),
            "subscription": obj.get("subscription"),
            "user": obj.get("user"),
            "activated_at": obj.get("activatedAt"),
            "canceled_at": obj.get("canceledAt"),
            "created_at": obj.get("createdAt"),
            "ended_at": obj.get("endedAt")
        })
        return _obj

