# 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, List, Optional, Union
from pydantic import BaseModel, Field, StrictBool, StrictFloat, StrictInt, StrictStr, conlist, constr, validator
from marqeta_client.models.account_funding_request import AccountFundingRequest
from marqeta_client.models.acquirer import Acquirer
from marqeta_client.models.advanced_auth_card_acceptor_model import AdvancedAuthCardAcceptorModel
from marqeta_client.models.advanced_auth_card_options import AdvancedAuthCardOptions
from marqeta_client.models.advanced_auth_poi import AdvancedAuthPOI
from marqeta_client.models.digital_wallet_token_device import DigitalWalletTokenDevice
from marqeta_client.models.digital_wallet_token_wallet_provider import DigitalWalletTokenWalletProvider
from marqeta_client.models.iso8583_digital_wallet_token import Iso8583DigitalWalletToken
from marqeta_client.models.network_fee_model import NetworkFeeModel
from marqeta_client.models.network_metadata import NetworkMetadata
from marqeta_client.models.original_data_elements import OriginalDataElements
from marqeta_client.models.replacement_amount import ReplacementAmount
from marqeta_client.models.transaction_options import TransactionOptions
from marqeta_client.models.webhook import Webhook

class AdvAuthRequestModel(BaseModel):
    """
    AdvAuthRequestModel
    """
    extended_stip_reason_code: Optional[StrictStr] = Field(None, alias="extendedStipReasonCode")
    mti: Optional[StrictStr] = Field(None, description="Default is 0100")
    network: StrictStr = ...
    sub_network: Optional[StrictStr] = Field(None, description="Defaults to VISANET if network is VISA")
    network_reference_id: Optional[StrictStr] = None
    local_transaction_date: Optional[datetime] = Field(None, description="yyyy-MM-dd, yyyy-MM-ddThh:mm:ssZ")
    transaction_date: Optional[datetime] = Field(None, description="yyyy-MM-dd, yyyy-MM-ddThh:mm:ssZ")
    settlement_date: Optional[datetime] = Field(None, description="yyyy-MM-dd, yyyy-MM-ddThh:mm:ssZ")
    stan: Optional[StrictStr] = None
    rrn: Optional[StrictStr] = None
    processing_code: Optional[StrictStr] = None
    function_code: Optional[StrictStr] = None
    reason_code: Optional[StrictStr] = None
    rejection_code: Optional[constr(strict=True, max_length=4, min_length=0)] = None
    acquirer_reference_id: Optional[StrictStr] = None
    forwarding_institution_id: Optional[constr(strict=True, max_length=11, min_length=11)] = None
    local_transaction_amount: Optional[Union[StrictFloat, StrictInt]] = None
    local_currency_code: Optional[StrictStr] = None
    settlement_amount: Optional[Union[StrictFloat, StrictInt]] = None
    cardholder_billing_amount: Optional[Union[StrictFloat, StrictInt]] = None
    cardholder_billing_conversion_rate: Optional[Union[StrictFloat, StrictInt]] = None
    cardholder_billing_currency: Optional[StrictStr] = None
    settlement_currency_code: Optional[StrictStr] = None
    cardholder_settlement_conversion_rate: Optional[Union[StrictFloat, StrictInt]] = None
    approval_code: Optional[StrictStr] = None
    network_response: Optional[constr(strict=True, max_length=2, min_length=0)] = None
    stan_padding_length: Optional[StrictInt] = None
    acquirer: Optional[Acquirer] = None
    payment_account_reference: Optional[StrictStr] = None
    card_token: StrictStr = ...
    amount: Optional[Union[StrictFloat, StrictInt]] = None
    cash_back_amount: Optional[Union[StrictFloat, StrictInt]] = None
    mid: Optional[StrictStr] = None
    pin: Optional[StrictStr] = None
    pos_pan_entry_mode: Optional[StrictStr] = Field(None, description="Default is MAG_STRIPE")
    acquirer_fee_amount: Optional[Union[StrictFloat, StrictInt]] = None
    stip_reason_code: Optional[StrictStr] = None
    is_recurring: Optional[StrictBool] = Field(None, description="Default is false")
    is_installment: Optional[StrictBool] = Field(None, description="Default is false")
    network_fees: Optional[conlist(NetworkFeeModel)] = None
    card_acceptor: Optional[AdvancedAuthCardAcceptorModel] = None
    transaction_options: Optional[TransactionOptions] = None
    original_data_elements: Optional[OriginalDataElements] = None
    replacement_amount: Optional[ReplacementAmount] = None
    webhook: Optional[Webhook] = None
    digital_wallet_token: Optional[Iso8583DigitalWalletToken] = None
    digital_wallet_token_device_info: Optional[DigitalWalletTokenDevice] = None
    digital_wallet_token_wallet_provider_info: Optional[DigitalWalletTokenWalletProvider] = None
    raw_iso_fields: Optional[Dict[str, StrictStr]] = None
    cavv_result_code: Optional[StrictStr] = None
    acceptance_environment_authentication_outage_indicator: Optional[StrictStr] = None
    threeds_authentication_value: Optional[StrictStr] = None
    threeds_acquirer_exemption_value: Optional[StrictStr] = None
    security_level_indicator: Optional[StrictStr] = None
    secure_payment_application_v2_value: Optional[StrictStr] = None
    from_account: Optional[StrictStr] = None
    issuer_received_time: Optional[StrictStr] = None
    network_metadata: Optional[NetworkMetadata] = None
    isa_indicator: Optional[StrictStr] = None
    payment_facilitator_id: Optional[StrictStr] = None
    independent_sales_organization_id: Optional[StrictStr] = None
    sub_merchant_id: Optional[StrictStr] = None
    country_of_origin: Optional[StrictStr] = None
    foreign_retailer_indicator: Optional[StrictStr] = None
    currency_conversion_assessment: Optional[StrictStr] = None
    transfer_service_provider_name: Optional[StrictStr] = None
    payment_facilitator_name: Optional[StrictStr] = None
    network_assigned_id: Optional[StrictStr] = None
    account_funding: Optional[AccountFundingRequest] = None
    atc_value: Optional[Union[StrictFloat, StrictInt]] = None
    atc_discrepancy_value: Optional[Union[StrictFloat, StrictInt]] = None
    atc_discrepancy_indicator: Optional[StrictStr] = None
    poi: Optional[AdvancedAuthPOI] = None
    card_options: AdvancedAuthCardOptions = ...
    is_stip_approval: Optional[StrictBool] = None
    stip_advice_detail_code_override: Optional[StrictBool] = None
    __properties = ["extendedStipReasonCode", "mti", "network", "sub_network", "network_reference_id", "local_transaction_date", "transaction_date", "settlement_date", "stan", "rrn", "processing_code", "function_code", "reason_code", "rejection_code", "acquirer_reference_id", "forwarding_institution_id", "local_transaction_amount", "local_currency_code", "settlement_amount", "cardholder_billing_amount", "cardholder_billing_conversion_rate", "cardholder_billing_currency", "settlement_currency_code", "cardholder_settlement_conversion_rate", "approval_code", "network_response", "stan_padding_length", "acquirer", "payment_account_reference", "card_token", "amount", "cash_back_amount", "mid", "pin", "pos_pan_entry_mode", "acquirer_fee_amount", "stip_reason_code", "is_recurring", "is_installment", "network_fees", "card_acceptor", "transaction_options", "original_data_elements", "replacement_amount", "webhook", "digital_wallet_token", "digital_wallet_token_device_info", "digital_wallet_token_wallet_provider_info", "raw_iso_fields", "cavv_result_code", "acceptance_environment_authentication_outage_indicator", "threeds_authentication_value", "threeds_acquirer_exemption_value", "security_level_indicator", "secure_payment_application_v2_value", "from_account", "issuer_received_time", "network_metadata", "isa_indicator", "payment_facilitator_id", "independent_sales_organization_id", "sub_merchant_id", "country_of_origin", "foreign_retailer_indicator", "currency_conversion_assessment", "transfer_service_provider_name", "payment_facilitator_name", "network_assigned_id", "account_funding", "atc_value", "atc_discrepancy_value", "atc_discrepancy_indicator", "poi", "card_options", "is_stip_approval", "stip_advice_detail_code_override"]

    @validator('mti')
    def mti_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('0100', '0120', '0190', '0200', '0220', '0400', '0420', '0620', '0110', '0130', '0210', '0410', '0430', '0230'):
            raise ValueError("must be one of enum values ('0100', '0120', '0190', '0200', '0220', '0400', '0420', '0620', '0110', '0130', '0210', '0410', '0430', '0230')")
        return v

    @validator('network')
    def network_validate_enum(cls, v):
        if v not in ('MASTERCARD', 'DISCOVER', 'PULSE', 'VISA'):
            raise ValueError("must be one of enum values ('MASTERCARD', 'DISCOVER', 'PULSE', 'VISA')")
        return v

    @validator('sub_network')
    def sub_network_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('VISANET', 'VISANETDEBIT', 'VISAINTERLINK', 'VISAPLUS', 'MAESTRO'):
            raise ValueError("must be one of enum values ('VISANET', 'VISANETDEBIT', 'VISAINTERLINK', 'VISAPLUS', 'MAESTRO')")
        return v

    @validator('pos_pan_entry_mode')
    def pos_pan_entry_mode_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('MANUAL', 'MAG_STRIPE', 'MAG_STRIPE_CONTACTLESS', 'CHIP', 'CHIP_CONTACTLESS', 'BAR_CODE', 'OCR', 'MICR', 'OTHER'):
            raise ValueError("must be one of enum values ('MANUAL', 'MAG_STRIPE', 'MAG_STRIPE_CONTACTLESS', 'CHIP', 'CHIP_CONTACTLESS', 'BAR_CODE', 'OCR', 'MICR', 'OTHER')")
        return v

    @validator('cavv_result_code')
    def cavv_result_code_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D'):
            raise ValueError("must be one of enum values ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D')")
        return v

    @validator('isa_indicator')
    def isa_indicator_validate_enum(cls, v):
        if v is None:
            return v

        if v not in ('S', 'C', 'R', 'M', 'P', 'BLANK_SPACE'):
            raise ValueError("must be one of enum values ('S', 'C', 'R', 'M', 'P', 'BLANK_SPACE')")
        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) -> AdvAuthRequestModel:
        """Create an instance of AdvAuthRequestModel 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 acquirer
        if self.acquirer:
            _dict['acquirer'] = self.acquirer.to_dict()
        # override the default output from pydantic by calling `to_dict()` of each item in network_fees (list)
        _items = []
        if self.network_fees:
            for _item in self.network_fees:
                if _item:
                    _items.append(_item.to_dict())
            _dict['network_fees'] = _items
        # override the default output from pydantic by calling `to_dict()` of card_acceptor
        if self.card_acceptor:
            _dict['card_acceptor'] = self.card_acceptor.to_dict()
        # override the default output from pydantic by calling `to_dict()` of transaction_options
        if self.transaction_options:
            _dict['transaction_options'] = self.transaction_options.to_dict()
        # override the default output from pydantic by calling `to_dict()` of original_data_elements
        if self.original_data_elements:
            _dict['original_data_elements'] = self.original_data_elements.to_dict()
        # override the default output from pydantic by calling `to_dict()` of replacement_amount
        if self.replacement_amount:
            _dict['replacement_amount'] = self.replacement_amount.to_dict()
        # override the default output from pydantic by calling `to_dict()` of webhook
        if self.webhook:
            _dict['webhook'] = self.webhook.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 digital_wallet_token_device_info
        if self.digital_wallet_token_device_info:
            _dict['digital_wallet_token_device_info'] = self.digital_wallet_token_device_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of digital_wallet_token_wallet_provider_info
        if self.digital_wallet_token_wallet_provider_info:
            _dict['digital_wallet_token_wallet_provider_info'] = self.digital_wallet_token_wallet_provider_info.to_dict()
        # override the default output from pydantic by calling `to_dict()` of network_metadata
        if self.network_metadata:
            _dict['network_metadata'] = self.network_metadata.to_dict()
        # override the default output from pydantic by calling `to_dict()` of account_funding
        if self.account_funding:
            _dict['account_funding'] = self.account_funding.to_dict()
        # override the default output from pydantic by calling `to_dict()` of poi
        if self.poi:
            _dict['poi'] = self.poi.to_dict()
        # override the default output from pydantic by calling `to_dict()` of card_options
        if self.card_options:
            _dict['card_options'] = self.card_options.to_dict()
        return _dict

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

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

        _obj = AdvAuthRequestModel.parse_obj({
            "extended_stip_reason_code": obj.get("extendedStipReasonCode"),
            "mti": obj.get("mti"),
            "network": obj.get("network"),
            "sub_network": obj.get("sub_network"),
            "network_reference_id": obj.get("network_reference_id"),
            "local_transaction_date": obj.get("local_transaction_date"),
            "transaction_date": obj.get("transaction_date"),
            "settlement_date": obj.get("settlement_date"),
            "stan": obj.get("stan"),
            "rrn": obj.get("rrn"),
            "processing_code": obj.get("processing_code"),
            "function_code": obj.get("function_code"),
            "reason_code": obj.get("reason_code"),
            "rejection_code": obj.get("rejection_code"),
            "acquirer_reference_id": obj.get("acquirer_reference_id"),
            "forwarding_institution_id": obj.get("forwarding_institution_id"),
            "local_transaction_amount": obj.get("local_transaction_amount"),
            "local_currency_code": obj.get("local_currency_code"),
            "settlement_amount": obj.get("settlement_amount"),
            "cardholder_billing_amount": obj.get("cardholder_billing_amount"),
            "cardholder_billing_conversion_rate": obj.get("cardholder_billing_conversion_rate"),
            "cardholder_billing_currency": obj.get("cardholder_billing_currency"),
            "settlement_currency_code": obj.get("settlement_currency_code"),
            "cardholder_settlement_conversion_rate": obj.get("cardholder_settlement_conversion_rate"),
            "approval_code": obj.get("approval_code"),
            "network_response": obj.get("network_response"),
            "stan_padding_length": obj.get("stan_padding_length"),
            "acquirer": Acquirer.from_dict(obj.get("acquirer")) if obj.get("acquirer") is not None else None,
            "payment_account_reference": obj.get("payment_account_reference"),
            "card_token": obj.get("card_token"),
            "amount": obj.get("amount"),
            "cash_back_amount": obj.get("cash_back_amount"),
            "mid": obj.get("mid"),
            "pin": obj.get("pin"),
            "pos_pan_entry_mode": obj.get("pos_pan_entry_mode"),
            "acquirer_fee_amount": obj.get("acquirer_fee_amount"),
            "stip_reason_code": obj.get("stip_reason_code"),
            "is_recurring": obj.get("is_recurring"),
            "is_installment": obj.get("is_installment"),
            "network_fees": [NetworkFeeModel.from_dict(_item) for _item in obj.get("network_fees")] if obj.get("network_fees") is not None else None,
            "card_acceptor": AdvancedAuthCardAcceptorModel.from_dict(obj.get("card_acceptor")) if obj.get("card_acceptor") is not None else None,
            "transaction_options": TransactionOptions.from_dict(obj.get("transaction_options")) if obj.get("transaction_options") is not None else None,
            "original_data_elements": OriginalDataElements.from_dict(obj.get("original_data_elements")) if obj.get("original_data_elements") is not None else None,
            "replacement_amount": ReplacementAmount.from_dict(obj.get("replacement_amount")) if obj.get("replacement_amount") is not None else None,
            "webhook": Webhook.from_dict(obj.get("webhook")) if obj.get("webhook") is not None else None,
            "digital_wallet_token": Iso8583DigitalWalletToken.from_dict(obj.get("digital_wallet_token")) if obj.get("digital_wallet_token") is not None else None,
            "digital_wallet_token_device_info": DigitalWalletTokenDevice.from_dict(obj.get("digital_wallet_token_device_info")) if obj.get("digital_wallet_token_device_info") is not None else None,
            "digital_wallet_token_wallet_provider_info": DigitalWalletTokenWalletProvider.from_dict(obj.get("digital_wallet_token_wallet_provider_info")) if obj.get("digital_wallet_token_wallet_provider_info") is not None else None,
            "raw_iso_fields": obj.get("raw_iso_fields"),
            "cavv_result_code": obj.get("cavv_result_code"),
            "acceptance_environment_authentication_outage_indicator": obj.get("acceptance_environment_authentication_outage_indicator"),
            "threeds_authentication_value": obj.get("threeds_authentication_value"),
            "threeds_acquirer_exemption_value": obj.get("threeds_acquirer_exemption_value"),
            "security_level_indicator": obj.get("security_level_indicator"),
            "secure_payment_application_v2_value": obj.get("secure_payment_application_v2_value"),
            "from_account": obj.get("from_account"),
            "issuer_received_time": obj.get("issuer_received_time"),
            "network_metadata": NetworkMetadata.from_dict(obj.get("network_metadata")) if obj.get("network_metadata") is not None else None,
            "isa_indicator": obj.get("isa_indicator"),
            "payment_facilitator_id": obj.get("payment_facilitator_id"),
            "independent_sales_organization_id": obj.get("independent_sales_organization_id"),
            "sub_merchant_id": obj.get("sub_merchant_id"),
            "country_of_origin": obj.get("country_of_origin"),
            "foreign_retailer_indicator": obj.get("foreign_retailer_indicator"),
            "currency_conversion_assessment": obj.get("currency_conversion_assessment"),
            "transfer_service_provider_name": obj.get("transfer_service_provider_name"),
            "payment_facilitator_name": obj.get("payment_facilitator_name"),
            "network_assigned_id": obj.get("network_assigned_id"),
            "account_funding": AccountFundingRequest.from_dict(obj.get("account_funding")) if obj.get("account_funding") is not None else None,
            "atc_value": obj.get("atc_value"),
            "atc_discrepancy_value": obj.get("atc_discrepancy_value"),
            "atc_discrepancy_indicator": obj.get("atc_discrepancy_indicator"),
            "poi": AdvancedAuthPOI.from_dict(obj.get("poi")) if obj.get("poi") is not None else None,
            "card_options": AdvancedAuthCardOptions.from_dict(obj.get("card_options")) if obj.get("card_options") is not None else None,
            "is_stip_approval": obj.get("is_stip_approval"),
            "stip_advice_detail_code_override": obj.get("stip_advice_detail_code_override")
        })
        return _obj

