# 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_change_plan import SubscriptionChangePlan

class SubscriptionChange(BaseModel):
    """
    SubscriptionChange
    """
    object: Optional[Any] = Field(..., description="Type of object is always `subscriptionChange`.")
    id: Optional[Any] = Field(..., description="Unique identifier for the subscription change.")
    plan: SubscriptionChangePlan = Field(...)
    status: Optional[Any] = Field(..., description="The current status of the subscription change.")
    subscription: Optional[Any] = Field(..., description="Unique identifier of the subscription to be changed.")
    applied_at: Optional[Any] = Field(..., alias="appliedAt", description="Time when the subscription change was applied.")
    created_at: Optional[Any] = Field(..., alias="createdAt", description="Time when the subscription change was created.")
    scheduled_at: Optional[Any] = Field(..., alias="scheduledAt", description="Approximate time when the change should take place.")
    __properties = ["object", "id", "plan", "status", "subscription", "appliedAt", "createdAt", "scheduledAt"]

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

        if value not in ('pending', 'applied'):
            raise ValueError("must be one of enum values ('pending', 'applied')")
        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) -> SubscriptionChange:
        """Create an instance of SubscriptionChange 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 plan
        if self.plan:
            _dict['plan'] = self.plan.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 applied_at (nullable) is None
        # and __fields_set__ contains the field
        if self.applied_at is None and "applied_at" in self.__fields_set__:
            _dict['appliedAt'] = 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 scheduled_at (nullable) is None
        # and __fields_set__ contains the field
        if self.scheduled_at is None and "scheduled_at" in self.__fields_set__:
            _dict['scheduledAt'] = None

        return _dict

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

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

        _obj = SubscriptionChange.parse_obj({
            "object": obj.get("object"),
            "id": obj.get("id"),
            "plan": SubscriptionChangePlan.from_dict(obj.get("plan")) if obj.get("plan") is not None else None,
            "status": obj.get("status"),
            "subscription": obj.get("subscription"),
            "applied_at": obj.get("appliedAt"),
            "created_at": obj.get("createdAt"),
            "scheduled_at": obj.get("scheduledAt")
        })
        return _obj

