# 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.porting_donor_provider import PortingDonorProvider
from gigs_client.models.porting_recipient_provider import PortingRecipientProvider

class SubscriptionPorting(BaseModel):
    """
    Current porting (if any) related with the subscription.
    """
    object: Optional[Any] = Field(..., description="Type of object is always `porting`.")
    id: Optional[Any] = Field(..., description="Unique identifier for the porting.")
    account_number: Optional[Any] = Field(..., alias="accountNumber", description="The account number on the donor service provider.")
    birthday: Optional[Any] = Field(..., description="The birthday of the account holder on the donor service provider.")
    declined_attempts: Optional[Any] = Field(..., alias="declinedAttempts", description="The number of declined porting attempts so far.")
    declined_code: Optional[Any] = Field(..., alias="declinedCode", description="The code reason for the declined porting.  <!-- theme: info --> > #### Preview > > This property 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. ")
    declined_message: Optional[Any] = Field(..., alias="declinedMessage", description="The reason description for the declined porting.  <!-- theme: info --> > #### Preview > > This property 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. ")
    donor_provider: PortingDonorProvider = Field(..., alias="donorProvider")
    first_name: Optional[Any] = Field(..., alias="firstName", description="The first name of the account holder on the donor service provider.")
    last_name: Optional[Any] = Field(..., alias="lastName", description="The last name of the account holder on the donor service provider.")
    phone_number: Optional[Any] = Field(..., alias="phoneNumber", description="The phone number to port in E.164 format.")
    provider: Optional[Any] = Field(..., description="The ID of the recipient network provider.")
    recipient_provider: PortingRecipientProvider = Field(..., alias="recipientProvider")
    required: Optional[Any] = Field(..., description="List of fields required for the porting to be processable. The fields depend on the donor and recipient providers.")
    status: Optional[Any] = Field(..., description="The current status of the porting.")
    subscription: Optional[Any] = Field(..., description="Unique identifier for the porting subscription.")
    user: Optional[Any] = Field(..., description="Unique identifier for the user this porting is for.")
    canceled_at: Optional[Any] = Field(..., alias="canceledAt", description="Time when the porting was canceled.")
    completed_at: Optional[Any] = Field(..., alias="completedAt", description="Time when the porting was completed.")
    created_at: Optional[Any] = Field(..., alias="createdAt", description="Time when the porting was created.")
    expired_at: Optional[Any] = Field(..., alias="expiredAt", description="Time when the porting was expired.")
    last_declined_at: Optional[Any] = Field(..., alias="lastDeclinedAt", description="Time when the porting was last declined.")
    last_requested_at: Optional[Any] = Field(..., alias="lastRequestedAt", description="Time when the porting was last requested.")
    __properties = ["object", "id", "accountNumber", "birthday", "declinedAttempts", "declinedCode", "declinedMessage", "donorProvider", "firstName", "lastName", "phoneNumber", "provider", "recipientProvider", "required", "status", "subscription", "user", "canceledAt", "completedAt", "createdAt", "expiredAt", "lastDeclinedAt", "lastRequestedAt"]

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

        if value not in ('draft', 'pending', 'requested', 'declined', 'completed', 'canceled', 'expired'):
            raise ValueError("must be one of enum values ('draft', 'pending', 'requested', 'declined', 'completed', 'canceled', 'expired')")
        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) -> SubscriptionPorting:
        """Create an instance of SubscriptionPorting 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 donor_provider
        if self.donor_provider:
            _dict['donorProvider'] = self.donor_provider.to_dict()
        # override the default output from pydantic by calling `to_dict()` of recipient_provider
        if self.recipient_provider:
            _dict['recipientProvider'] = self.recipient_provider.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 account_number (nullable) is None
        # and __fields_set__ contains the field
        if self.account_number is None and "account_number" in self.__fields_set__:
            _dict['accountNumber'] = None

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

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

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

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

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

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

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

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

        # set to None if required (nullable) is None
        # and __fields_set__ contains the field
        if self.required is None and "required" in self.__fields_set__:
            _dict['required'] = 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 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 completed_at (nullable) is None
        # and __fields_set__ contains the field
        if self.completed_at is None and "completed_at" in self.__fields_set__:
            _dict['completedAt'] = 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 expired_at (nullable) is None
        # and __fields_set__ contains the field
        if self.expired_at is None and "expired_at" in self.__fields_set__:
            _dict['expiredAt'] = None

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

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

        return _dict

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

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

        _obj = SubscriptionPorting.parse_obj({
            "object": obj.get("object"),
            "id": obj.get("id"),
            "account_number": obj.get("accountNumber"),
            "birthday": obj.get("birthday"),
            "declined_attempts": obj.get("declinedAttempts"),
            "declined_code": obj.get("declinedCode"),
            "declined_message": obj.get("declinedMessage"),
            "donor_provider": PortingDonorProvider.from_dict(obj.get("donorProvider")) if obj.get("donorProvider") is not None else None,
            "first_name": obj.get("firstName"),
            "last_name": obj.get("lastName"),
            "phone_number": obj.get("phoneNumber"),
            "provider": obj.get("provider"),
            "recipient_provider": PortingRecipientProvider.from_dict(obj.get("recipientProvider")) if obj.get("recipientProvider") is not None else None,
            "required": obj.get("required"),
            "status": obj.get("status"),
            "subscription": obj.get("subscription"),
            "user": obj.get("user"),
            "canceled_at": obj.get("canceledAt"),
            "completed_at": obj.get("completedAt"),
            "created_at": obj.get("createdAt"),
            "expired_at": obj.get("expiredAt"),
            "last_declined_at": obj.get("lastDeclinedAt"),
            "last_requested_at": obj.get("lastRequestedAt")
        })
        return _obj

