# 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 typing import Dict, List, Optional, Union
from pydantic import BaseModel, StrictStr, confloat, conint, conlist, constr, validator
from marqeta_client.models.cardholder_balance import CardholderBalance
from marqeta_client.models.jit_address_verification import JitAddressVerification

class JitFundingApi(BaseModel):
    """
    JitFundingApi
    """
    token: constr(strict=True, max_length=36, min_length=0) = ...
    method: StrictStr = ...
    user_token: constr(strict=True, max_length=36, min_length=0) = ...
    acting_user_token: Optional[constr(strict=True, max_length=36, min_length=0)] = None
    business_token: Optional[constr(strict=True, max_length=36, min_length=0)] = None
    amount: Union[confloat(ge=0, strict=True), conint(ge=0, strict=True)] = ...
    memo: Optional[constr(strict=True, max_length=99, min_length=0)] = None
    tags: Optional[constr(strict=True, max_length=255, min_length=0)] = None
    original_jit_funding_token: Optional[constr(strict=True, max_length=36, min_length=0)] = None
    incremental_authorization_jit_funding_tokens: Optional[conlist(StrictStr)] = None
    address_verification: Optional[JitAddressVerification] = None
    decline_reason: Optional[StrictStr] = None
    balances: Optional[Dict[str, CardholderBalance]] = None
    __properties = ["token", "method", "user_token", "acting_user_token", "business_token", "amount", "memo", "tags", "original_jit_funding_token", "incremental_authorization_jit_funding_tokens", "address_verification", "decline_reason", "balances"]

    @validator('method')
    def method_validate_enum(cls, v):
        if v not in ('pgfs.authorization', 'pgfs.balanceinquiry', 'pgfs.authorization.incremental', 'pgfs.authorization.capture', 'pgfs.authorization.reversal', 'pgfs.auth_plus_capture', 'pgfs.refund', 'pgfs.force_capture', 'pgfs.authorization.capture.chargeback', 'pgfs.authorization.capture.chargeback.reversal', 'pgfs.pindebit.chargeback', 'pgfs.pindebit.chargeback.reversal', 'pgfs.dispute.credit', 'pgfs.dispute.debit', 'pgfs.directdeposit.credit', 'pgfs.directdeposit.debit', 'pgfs.directdeposit.credit.reversal', 'pgfs.directdeposit.debit.reversal', 'pgfs.adjustment.credit', 'pgfs.adjustment.debit', 'pgfs.auth_plus_capture.standin', 'pgfs.authorization.standin', 'pgfs.network.load', 'pgfs.original.credit.authorization', 'pgfs.original.credit.auth_plus_capture', 'pgfs.refund.authorization', 'pgfs.refund.authorization.reversalpgfs.billpayment', 'pgfs.billpayment.capture', 'pgfs.billpayment.reversal', 'pgfs.authorization.account_verification'):
            raise ValueError("must be one of enum values ('pgfs.authorization', 'pgfs.balanceinquiry', 'pgfs.authorization.incremental', 'pgfs.authorization.capture', 'pgfs.authorization.reversal', 'pgfs.auth_plus_capture', 'pgfs.refund', 'pgfs.force_capture', 'pgfs.authorization.capture.chargeback', 'pgfs.authorization.capture.chargeback.reversal', 'pgfs.pindebit.chargeback', 'pgfs.pindebit.chargeback.reversal', 'pgfs.dispute.credit', 'pgfs.dispute.debit', 'pgfs.directdeposit.credit', 'pgfs.directdeposit.debit', 'pgfs.directdeposit.credit.reversal', 'pgfs.directdeposit.debit.reversal', 'pgfs.adjustment.credit', 'pgfs.adjustment.debit', 'pgfs.auth_plus_capture.standin', 'pgfs.authorization.standin', 'pgfs.network.load', 'pgfs.original.credit.authorization', 'pgfs.original.credit.auth_plus_capture', 'pgfs.refund.authorization', 'pgfs.refund.authorization.reversalpgfs.billpayment', 'pgfs.billpayment.capture', 'pgfs.billpayment.reversal', 'pgfs.authorization.account_verification')")
        return v

    @validator('decline_reason')
    def decline_reason_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('INVALID_AMOUNT', 'INSUFFICIENT_FUNDS', 'TRANSACTION_NOT_PERMITTED', 'SUSPECTED_FRAUD', 'AMOUNT_LIMIT_EXCEEDED', 'TRANSACTION_COUNT_LIMIT_EXCEEDED', 'DUPLICATE_TRANSACTION', 'INVALID_MERCHANT', 'INVALID_CARD', 'NO_CREDIT_ACCOUNT', 'EXPIRED_CARD', 'NO_CHECKING_ACCOUNT', 'NO_SAVINGS_ACCOUNT', 'STOP_PAYMENT', 'REVOCATION_AUTHORIZATION_ORDER', 'REVOCATION_ALL_AUTHORIZATION_ORDER', 'SOFT_DECLINE_AUTHENTICATION_REQUIRED', 'CLOSED_ACCOUNT', 'SOFT_DECLINE_PIN_REQUIRED', 'CARD_NOT_ACTIVE', 'CARDHOLDER_NOT_ACTIVE'):
            raise ValueError("must be one of enum values ('INVALID_AMOUNT', 'INSUFFICIENT_FUNDS', 'TRANSACTION_NOT_PERMITTED', 'SUSPECTED_FRAUD', 'AMOUNT_LIMIT_EXCEEDED', 'TRANSACTION_COUNT_LIMIT_EXCEEDED', 'DUPLICATE_TRANSACTION', 'INVALID_MERCHANT', 'INVALID_CARD', 'NO_CREDIT_ACCOUNT', 'EXPIRED_CARD', 'NO_CHECKING_ACCOUNT', 'NO_SAVINGS_ACCOUNT', 'STOP_PAYMENT', 'REVOCATION_AUTHORIZATION_ORDER', 'REVOCATION_ALL_AUTHORIZATION_ORDER', 'SOFT_DECLINE_AUTHENTICATION_REQUIRED', 'CLOSED_ACCOUNT', 'SOFT_DECLINE_PIN_REQUIRED', 'CARD_NOT_ACTIVE', 'CARDHOLDER_NOT_ACTIVE')")
        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) -> JitFundingApi:
        """Create an instance of JitFundingApi 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 address_verification
        if self.address_verification:
            _dict['address_verification'] = self.address_verification.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each value in balances (dict)
        _field_dict = {}
        if self.balances:
            for _key in self.balances:
                if self.balances[_key]:
                    _field_dict[_key] = self.balances[_key].to_dict()
            _dict['balances'] = _field_dict
        return _dict

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

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

        _obj = JitFundingApi.parse_obj({
            "token": obj.get("token"),
            "method": obj.get("method"),
            "user_token": obj.get("user_token"),
            "acting_user_token": obj.get("acting_user_token"),
            "business_token": obj.get("business_token"),
            "amount": obj.get("amount"),
            "memo": obj.get("memo"),
            "tags": obj.get("tags"),
            "original_jit_funding_token": obj.get("original_jit_funding_token"),
            "incremental_authorization_jit_funding_tokens": obj.get("incremental_authorization_jit_funding_tokens"),
            "address_verification": JitAddressVerification.from_dict(obj.get("address_verification")) if obj.get("address_verification") is not None else None,
            "decline_reason": obj.get("decline_reason"),
            "balances": dict(
                (_k, CardholderBalance.from_dict(_v))
                for _k, _v in obj.get("balances").items()
            )
            if obj.get("balances") is not None
            else None
        })
        return _obj

