# 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 Optional
from pydantic import BaseModel, StrictBool, StrictStr, constr, validator
from marqeta_client.models.card_fulfillment_request import CardFulfillmentRequest
from marqeta_client.models.card_metadata import CardMetadata
from marqeta_client.models.cardholder_metadata import CardholderMetadata
from marqeta_client.models.validations_response import ValidationsResponse

class CardTransitionResponse(BaseModel):
    """
    CardTransitionResponse
    """
    token: constr(strict=True, max_length=36, min_length=1) = ...
    card_token: constr(strict=True, max_length=36, min_length=1) = ...
    user_token: constr(strict=True, max_length=36, min_length=1) = ...
    state: StrictStr = ...
    reason: Optional[constr(strict=True, max_length=255, min_length=0)] = None
    reason_code: Optional[StrictStr] = None
    channel: StrictStr = ...
    fulfillment_status: StrictStr = ...
    validations: Optional[ValidationsResponse] = None
    type: StrictStr = ...
    created_time: Optional[datetime] = None
    card_product_token: constr(strict=True, max_length=36, min_length=0) = ...
    last_four: StrictStr = ...
    pan: StrictStr = ...
    expiration: StrictStr = ...
    expiration_time: StrictStr = ...
    barcode: StrictStr = ...
    pin_is_set: StrictBool = ...
    fulfillment: Optional[CardFulfillmentRequest] = None
    bulk_issuance_token: Optional[StrictStr] = None
    reissue_pan_from_card_token: Optional[StrictStr] = None
    new_pan_from_card_token: Optional[StrictStr] = None
    user: Optional[CardholderMetadata] = None
    card: Optional[CardMetadata] = None
    expedite: Optional[StrictBool] = False
    __properties = ["token", "card_token", "user_token", "state", "reason", "reason_code", "channel", "fulfillment_status", "validations", "type", "created_time", "card_product_token", "last_four", "pan", "expiration", "expiration_time", "barcode", "pin_is_set", "fulfillment", "bulk_issuance_token", "reissue_pan_from_card_token", "new_pan_from_card_token", "user", "card", "expedite"]

    @validator('state')
    def state_validate_enum(cls, v):
        if v not in ('ACTIVE', 'SUSPENDED', 'TERMINATED', 'UNACTIVATED'):
            raise ValueError("must be one of enum values ('ACTIVE', 'SUSPENDED', 'TERMINATED', 'UNACTIVATED')")
        return v

    @validator('reason_code')
    def reason_code_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31'):
            raise ValueError("must be one of enum values ('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31')")
        return v

    @validator('channel')
    def channel_validate_enum(cls, v):
        if v not in ('API', 'IVR', 'FRAUD', 'ADMIN', 'SYSTEM'):
            raise ValueError("must be one of enum values ('API', 'IVR', 'FRAUD', 'ADMIN', 'SYSTEM')")
        return v

    @validator('fulfillment_status')
    def fulfillment_status_validate_enum(cls, v):
        if v not in ('ISSUED', 'ORDERED', 'REJECTED', 'SHIPPED', 'DELIVERED', 'DIGITALLY_PRESENTED'):
            raise ValueError("must be one of enum values ('ISSUED', 'ORDERED', 'REJECTED', 'SHIPPED', 'DELIVERED', 'DIGITALLY_PRESENTED')")
        return v

    @validator('type')
    def type_validate_enum(cls, v):
        if v not in ('fulfillment.issued', 'state.activated', 'state.suspended', 'state.reinstated', 'state.terminated', 'state.limited', 'fulfillment.ordered', 'fulfillment.rejected', 'fulfillment.shipped', 'fulfillment.delivered', 'fulfillment.digitally_presented'):
            raise ValueError("must be one of enum values ('fulfillment.issued', 'state.activated', 'state.suspended', 'state.reinstated', 'state.terminated', 'state.limited', 'fulfillment.ordered', 'fulfillment.rejected', 'fulfillment.shipped', 'fulfillment.delivered', 'fulfillment.digitally_presented')")
        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) -> CardTransitionResponse:
        """Create an instance of CardTransitionResponse 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={
                            "type",
                          },
                          exclude_none=True)
        # override the default output from pydantic by calling `to_dict()` of validations
        if self.validations:
            _dict['validations'] = self.validations.to_dict()
        # override the default output from pydantic by calling `to_dict()` of fulfillment
        if self.fulfillment:
            _dict['fulfillment'] = self.fulfillment.to_dict()
        # 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
        if self.card:
            _dict['card'] = self.card.to_dict()
        return _dict

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

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

        _obj = CardTransitionResponse.parse_obj({
            "token": obj.get("token"),
            "card_token": obj.get("card_token"),
            "user_token": obj.get("user_token"),
            "state": obj.get("state"),
            "reason": obj.get("reason"),
            "reason_code": obj.get("reason_code"),
            "channel": obj.get("channel"),
            "fulfillment_status": obj.get("fulfillment_status"),
            "validations": ValidationsResponse.from_dict(obj.get("validations")) if obj.get("validations") is not None else None,
            "type": obj.get("type"),
            "created_time": obj.get("created_time"),
            "card_product_token": obj.get("card_product_token"),
            "last_four": obj.get("last_four"),
            "pan": obj.get("pan"),
            "expiration": obj.get("expiration"),
            "expiration_time": obj.get("expiration_time"),
            "barcode": obj.get("barcode"),
            "pin_is_set": obj.get("pin_is_set") if obj.get("pin_is_set") is not None else False,
            "fulfillment": CardFulfillmentRequest.from_dict(obj.get("fulfillment")) if obj.get("fulfillment") is not None else None,
            "bulk_issuance_token": obj.get("bulk_issuance_token"),
            "reissue_pan_from_card_token": obj.get("reissue_pan_from_card_token"),
            "new_pan_from_card_token": obj.get("new_pan_from_card_token"),
            "user": CardholderMetadata.from_dict(obj.get("user")) if obj.get("user") is not None else None,
            "card": CardMetadata.from_dict(obj.get("card")) if obj.get("card") is not None else None,
            "expedite": obj.get("expedite") if obj.get("expedite") is not None else False
        })
        return _obj

