# coding: utf-8

"""
    Marqeta Core API

    Simplified management of your payment programs  # noqa: E501

    The version of the OpenAPI document: 3.0.0
    Contact: dev@swadesh.co
    Generated by OpenAPI Generator (https://openapi-generator.tech)

    Do not edit the class manually.
"""


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

from datetime import datetime
from typing import Dict, Optional, Union
from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, validator
from marqeta_client.models.internal_card_product import InternalCardProduct
from marqeta_client.models.internal_user import InternalUser

class InternalCard(BaseModel):
    """
    InternalCard
    """
    hash: Optional[StrictStr] = None
    kid: Optional[StrictStr] = None
    secure_data: Optional[StrictStr] = Field(None, alias="secureData")
    service_code: Optional[StrictStr] = Field(None, alias="serviceCode")
    id: StrictInt = ...
    token: StrictStr = ...
    user: InternalUser = ...
    card_product: InternalCardProduct = ...
    last_four: StrictStr = ...
    expiration_time: Optional[datetime] = None
    state: Optional[StrictStr] = None
    metadata: Optional[Dict[str, StrictStr]] = None
    card_pin_block: Optional[StrictStr] = None
    contactless_consecutive_total_spend: Optional[Union[StrictFloat, StrictInt]] = None
    contactless_consecutive_count: Optional[StrictInt] = None
    lvp_consecutive_total_spend: Optional[Union[StrictFloat, StrictInt]] = None
    lvp_consecutive_count: Optional[StrictInt] = None
    is_offline_pin_set_required: Optional[StrictBool] = None
    __properties = ["hash", "kid", "secureData", "serviceCode", "id", "token", "user", "card_product", "last_four", "expiration_time", "state", "metadata", "card_pin_block", "contactless_consecutive_total_spend", "contactless_consecutive_count", "lvp_consecutive_total_spend", "lvp_consecutive_count", "is_offline_pin_set_required"]

    @validator('state')
    def state_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('ACTIVE', 'SUSPENDED', 'TERMINATED', 'UNSUPPORTED', 'UNACTIVATED', 'LIMITED'):
            raise ValueError("must be one of enum values ('ACTIVE', 'SUSPENDED', 'TERMINATED', 'UNSUPPORTED', 'UNACTIVATED', 'LIMITED')")
        return v

    class Config:
        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) -> InternalCard:
        """Create an instance of InternalCard 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 user
        if self.user:
            _dict['user'] = self.user.to_dict()
        # override the default output from pydantic by calling `to_dict()` of card_product
        if self.card_product:
            _dict['card_product'] = self.card_product.to_dict()
        return _dict

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

        if type(obj) is not dict:
            return InternalCard.parse_obj(obj)

        _obj = InternalCard.parse_obj({
            "hash": obj.get("hash"),
            "kid": obj.get("kid"),
            "secure_data": obj.get("secureData"),
            "service_code": obj.get("serviceCode"),
            "id": obj.get("id"),
            "token": obj.get("token"),
            "user": InternalUser.from_dict(obj.get("user")) if obj.get("user") is not None else None,
            "card_product": InternalCardProduct.from_dict(obj.get("card_product")) if obj.get("card_product") is not None else None,
            "last_four": obj.get("last_four"),
            "expiration_time": obj.get("expiration_time"),
            "state": obj.get("state"),
            "metadata": obj.get("metadata"),
            "card_pin_block": obj.get("card_pin_block"),
            "contactless_consecutive_total_spend": obj.get("contactless_consecutive_total_spend"),
            "contactless_consecutive_count": obj.get("contactless_consecutive_count"),
            "lvp_consecutive_total_spend": obj.get("lvp_consecutive_total_spend"),
            "lvp_consecutive_count": obj.get("lvp_consecutive_count"),
            "is_offline_pin_set_required": obj.get("is_offline_pin_set_required")
        })
        return _obj

