# 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, StrictFloat, StrictInt, StrictStr, validator
from marqeta_client.models.internal_account import InternalAccount
from marqeta_client.models.internal_authorization_transaction import InternalAuthorizationTransaction
from marqeta_client.models.internal_card import InternalCard
from marqeta_client.models.internal_digital_wallet import InternalDigitalWallet
from marqeta_client.models.internal_gateway_log import InternalGatewayLog
from marqeta_client.models.internal_gpa_order import InternalGPAOrder
from marqeta_client.models.internal_user import InternalUser
from marqeta_client.models.transaction_model import TransactionModel

class FundingTranlog(BaseModel):
    """
    FundingTranlog
    """
    returned_balances: Optional[StrictStr] = Field(None, alias="returnedBalances")
    tags: Optional[StrictStr] = None
    transaction_type: StrictStr = Field(..., alias="transactionType")
    token: StrictStr = ...
    ref_transaction: Optional[InternalAuthorizationTransaction] = None
    node: StrictStr = ...
    network: StrictStr = ...
    sub_network: StrictStr = Field(..., alias="subNetwork")
    mid: Optional[StrictStr] = None
    tid: Optional[StrictStr] = None
    stan: Optional[StrictStr] = None
    ca_name: Optional[StrictStr] = None
    ca_street: Optional[StrictStr] = None
    ca_zip: Optional[StrictStr] = None
    ca_city: Optional[StrictStr] = None
    ca_region: Optional[StrictStr] = None
    ca_country: Optional[StrictStr] = None
    function_code: Optional[StrictStr] = Field(None, alias="functionCode")
    reason_code: Optional[StrictStr] = Field(None, alias="reasonCode")
    response_code: Optional[StrictStr] = Field(None, alias="responseCode")
    approval_number: Optional[StrictStr] = Field(None, alias="approvalNumber")
    display_message: Optional[StrictStr] = Field(None, alias="displayMessage")
    var_date: Optional[datetime] = Field(None, alias="date")
    transmission_date: Optional[datetime] = Field(None, alias="transmissionDate")
    local_transaction_date: Optional[datetime] = Field(None, alias="localTransactionDate")
    capture_date: Optional[datetime] = Field(None, alias="captureDate")
    settlement_date: Optional[datetime] = Field(None, alias="settlementDate")
    itc: Optional[StrictStr] = None
    irc: Optional[StrictStr] = None
    currency_code: Optional[StrictStr] = Field(None, alias="currencyCode")
    amount: Optional[Union[StrictFloat, StrictInt]] = None
    additional_amount: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="additionalAmount")
    acquirer_fee: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="acquirerFee")
    issuer_fee: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="issuerFee")
    rc: Optional[StrictStr] = None
    extrc: Optional[StrictStr] = None
    duration: Optional[StrictInt] = None
    cardholder: Optional[InternalUser] = None
    acting_cardholder: Optional[InternalUser] = Field(None, alias="actingCardholder")
    card: Optional[InternalCard] = None
    account: Optional[InternalAccount] = None
    account2: Optional[InternalAccount] = None
    mcc: Optional[StrictStr] = None
    network_reference_id: Optional[StrictStr] = Field(None, alias="networkReferenceId")
    acquirer_reference_id: Optional[StrictStr] = Field(None, alias="acquirerReferenceId")
    retrieval_reference_number: Optional[StrictStr] = Field(None, alias="retrievalReferenceNumber")
    forwarding_inst_id: Optional[StrictStr] = Field(None, alias="forwardingInstId")
    network_mid: Optional[StrictStr] = Field(None, alias="networkMid")
    request_amount: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="requestAmount")
    transaction_state: Optional[StrictStr] = Field(None, alias="transactionState")
    remote_host: Optional[StrictStr] = Field(None, alias="remoteHost")
    response_amount: Optional[Union[StrictFloat, StrictInt]] = Field(None, alias="responseAmount")
    expiration_time: Optional[datetime] = Field(None, alias="expirationTime")
    incoming_network_request_itc: Optional[StrictStr] = Field(None, alias="incomingNetworkRequestITC")
    digital_wallet_token: Optional[InternalDigitalWallet] = None
    tranlog_attributes: Optional[Dict[str, StrictStr]] = Field(None, alias="tranlogAttributes")
    payload: Optional[TransactionModel] = None
    layer: Optional[StrictInt] = None
    transaction_name: Optional[StrictStr] = None
    originator: Optional[StrictStr] = None
    acquirer: Optional[StrictStr] = None
    gpaorder: InternalGPAOrder = ...
    gateway_log: InternalGatewayLog = Field(..., alias="gatewayLog")
    __properties = ["returnedBalances", "tags", "transactionType", "token", "ref_transaction", "node", "network", "subNetwork", "mid", "tid", "stan", "ca_name", "ca_street", "ca_zip", "ca_city", "ca_region", "ca_country", "functionCode", "reasonCode", "responseCode", "approvalNumber", "displayMessage", "date", "transmissionDate", "localTransactionDate", "captureDate", "settlementDate", "itc", "irc", "currencyCode", "amount", "additionalAmount", "acquirerFee", "issuerFee", "rc", "extrc", "duration", "cardholder", "actingCardholder", "card", "account", "account2", "mcc", "networkReferenceId", "acquirerReferenceId", "retrievalReferenceNumber", "forwardingInstId", "networkMid", "requestAmount", "transactionState", "remoteHost", "responseAmount", "expirationTime", "incomingNetworkRequestITC", "digital_wallet_token", "tranlogAttributes", "payload", "layer", "transaction_name", "originator", "acquirer", "gpaorder", "gatewayLog"]

    @validator('transaction_state')
    def transaction_state_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('PENDING', 'CLEARED', 'COMPLETION', 'DECLINED', 'ERROR', 'ALL'):
            raise ValueError("must be one of enum values ('PENDING', 'CLEARED', 'COMPLETION', 'DECLINED', 'ERROR', 'ALL')")
        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) -> FundingTranlog:
        """Create an instance of FundingTranlog 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 ref_transaction
        if self.ref_transaction:
            _dict['ref_transaction'] = self.ref_transaction.to_dict()
        # override the default output from pydantic by calling `to_dict()` of cardholder
        if self.cardholder:
            _dict['cardholder'] = self.cardholder.to_dict()
        # override the default output from pydantic by calling `to_dict()` of acting_cardholder
        if self.acting_cardholder:
            _dict['actingCardholder'] = self.acting_cardholder.to_dict()
        # override the default output from pydantic by calling `to_dict()` of card
        if self.card:
            _dict['card'] = self.card.to_dict()
        # override the default output from pydantic by calling `to_dict()` of account
        if self.account:
            _dict['account'] = self.account.to_dict()
        # override the default output from pydantic by calling `to_dict()` of account2
        if self.account2:
            _dict['account2'] = self.account2.to_dict()
        # override the default output from pydantic by calling `to_dict()` of digital_wallet_token
        if self.digital_wallet_token:
            _dict['digital_wallet_token'] = self.digital_wallet_token.to_dict()
        # override the default output from pydantic by calling `to_dict()` of payload
        if self.payload:
            _dict['payload'] = self.payload.to_dict()
        # override the default output from pydantic by calling `to_dict()` of gpaorder
        if self.gpaorder:
            _dict['gpaorder'] = self.gpaorder.to_dict()
        # override the default output from pydantic by calling `to_dict()` of gateway_log
        if self.gateway_log:
            _dict['gatewayLog'] = self.gateway_log.to_dict()
        return _dict

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

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

        _obj = FundingTranlog.parse_obj({
            "returned_balances": obj.get("returnedBalances"),
            "tags": obj.get("tags"),
            "transaction_type": obj.get("transactionType"),
            "token": obj.get("token"),
            "ref_transaction": InternalAuthorizationTransaction.from_dict(obj.get("ref_transaction")) if obj.get("ref_transaction") is not None else None,
            "node": obj.get("node"),
            "network": obj.get("network"),
            "sub_network": obj.get("subNetwork"),
            "mid": obj.get("mid"),
            "tid": obj.get("tid"),
            "stan": obj.get("stan"),
            "ca_name": obj.get("ca_name"),
            "ca_street": obj.get("ca_street"),
            "ca_zip": obj.get("ca_zip"),
            "ca_city": obj.get("ca_city"),
            "ca_region": obj.get("ca_region"),
            "ca_country": obj.get("ca_country"),
            "function_code": obj.get("functionCode"),
            "reason_code": obj.get("reasonCode"),
            "response_code": obj.get("responseCode"),
            "approval_number": obj.get("approvalNumber"),
            "display_message": obj.get("displayMessage"),
            "var_date": obj.get("date"),
            "transmission_date": obj.get("transmissionDate"),
            "local_transaction_date": obj.get("localTransactionDate"),
            "capture_date": obj.get("captureDate"),
            "settlement_date": obj.get("settlementDate"),
            "itc": obj.get("itc"),
            "irc": obj.get("irc"),
            "currency_code": obj.get("currencyCode"),
            "amount": obj.get("amount"),
            "additional_amount": obj.get("additionalAmount"),
            "acquirer_fee": obj.get("acquirerFee"),
            "issuer_fee": obj.get("issuerFee"),
            "rc": obj.get("rc"),
            "extrc": obj.get("extrc"),
            "duration": obj.get("duration"),
            "cardholder": InternalUser.from_dict(obj.get("cardholder")) if obj.get("cardholder") is not None else None,
            "acting_cardholder": InternalUser.from_dict(obj.get("actingCardholder")) if obj.get("actingCardholder") is not None else None,
            "card": InternalCard.from_dict(obj.get("card")) if obj.get("card") is not None else None,
            "account": InternalAccount.from_dict(obj.get("account")) if obj.get("account") is not None else None,
            "account2": InternalAccount.from_dict(obj.get("account2")) if obj.get("account2") is not None else None,
            "mcc": obj.get("mcc"),
            "network_reference_id": obj.get("networkReferenceId"),
            "acquirer_reference_id": obj.get("acquirerReferenceId"),
            "retrieval_reference_number": obj.get("retrievalReferenceNumber"),
            "forwarding_inst_id": obj.get("forwardingInstId"),
            "network_mid": obj.get("networkMid"),
            "request_amount": obj.get("requestAmount"),
            "transaction_state": obj.get("transactionState"),
            "remote_host": obj.get("remoteHost"),
            "response_amount": obj.get("responseAmount"),
            "expiration_time": obj.get("expirationTime"),
            "incoming_network_request_itc": obj.get("incomingNetworkRequestITC"),
            "digital_wallet_token": InternalDigitalWallet.from_dict(obj.get("digital_wallet_token")) if obj.get("digital_wallet_token") is not None else None,
            "tranlog_attributes": obj.get("tranlogAttributes"),
            "payload": TransactionModel.from_dict(obj.get("payload")) if obj.get("payload") is not None else None,
            "layer": obj.get("layer"),
            "transaction_name": obj.get("transaction_name"),
            "originator": obj.get("originator"),
            "acquirer": obj.get("acquirer"),
            "gpaorder": InternalGPAOrder.from_dict(obj.get("gpaorder")) if obj.get("gpaorder") is not None else None,
            "gateway_log": InternalGatewayLog.from_dict(obj.get("gatewayLog")) if obj.get("gatewayLog") is not None else None
        })
        return _obj

