public static ACTypeEnum TerminalActionAnalysis(KernelDatabaseBase database)
        {
            TERMINAL_VERIFICATION_RESULTS_95_KRN tvr = new TERMINAL_VERIFICATION_RESULTS_95_KRN(database);
            ulong tvrAsNumber = Formatting.ConvertToInt64(tvr.Value.Value);
            ulong tacAsNumber = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.TERMINAL_ACTION_CODE_DENIAL_DF8121_KRN2).Value);

            #region taa.1
            if (database.IsNotEmpty(EMVTagsEnum.ISSUER_ACTION_CODE_DENIAL_9F0E_KRN.Tag))
            #endregion
            {
                #region taa.4
                ulong iacAsNumber = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.ISSUER_ACTION_CODE_DENIAL_9F0E_KRN).Value);
                if (!(
                        ((tacAsNumber | iacAsNumber) & tvrAsNumber) == 0)
                    )
                #endregion
                {
                    #region taa.5
                    Logger.Log("Declining: !(((tacAsNumber | iacAsNumber) & tvrAsNumber) == 0)):" + ((tacAsNumber | iacAsNumber) & tvrAsNumber));
                    Logger.Log("tacAsNumber: " + tacAsNumber);
                    Logger.Log("iacAsNumber: " + iacAsNumber);
                    int depth = 0;
                    Logger.Log(tvr.ToPrintString(ref depth));
                    return(ACTypeEnum.AAC);

                    #endregion
                }
            }
            else
            {
                #region taa.2
                if (!((tacAsNumber & tvrAsNumber) == 0))
                #endregion
                {
                    #region taa.3
                    Logger.Log("Declining: !((tacAsNumber & tvrAsNumber) == 0)");
                    Logger.Log("tacAsNumber: " + tacAsNumber);
                    int depth = 0;
                    Logger.Log(tvr.ToPrintString(ref depth));
                    return(ACTypeEnum.AAC);

                    #endregion
                }
            }

            #region taa.4.1
            TERMINAL_TYPE_9F35_KRN tt = new TERMINAL_TYPE_9F35_KRN(database);
            if (tt.Value.TerminalType.Code == 0x11 || tt.Value.TerminalType.Code == 0x21 ||
                tt.Value.TerminalType.Code == 0x14 || tt.Value.TerminalType.Code == 0x24 ||
                tt.Value.TerminalType.Code == 0x34)
            #endregion
            {
                #region taa.4.2
                return(ACTypeEnum.ARQC);

                #endregion
            }

            #region taa.6
            if (tt.Value.TerminalType.Code == 0x23 || tt.Value.TerminalType.Code == 0x26 ||
                tt.Value.TerminalType.Code == 0x36 || tt.Value.TerminalType.Code == 0x13 ||
                tt.Value.TerminalType.Code == 0x16)
            #endregion
            {
                #region taa.13
                if (database.IsNotEmpty(EMVTagsEnum.ISSUER_ACTION_CODE_DEFAULT_9F0D_KRN.Tag))
                #endregion
                {
                    ulong iacDefaultNumber  = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.ISSUER_ACTION_CODE_DEFAULT_9F0D_KRN).Value);
                    ulong taDefaultAsNumber = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.TERMINAL_ACTION_CODE_DEFAULT_DF8120_KRN2).Value);
                    #region taa.16
                    if (((iacDefaultNumber | taDefaultAsNumber) & tvrAsNumber) == 0)
                    #endregion
                    {
                        #region taa.18
                        return(ACTypeEnum.TC);

                        #endregion
                    }
                    else
                    {
                        #region taa.17
                        Logger.Log("Declining: ((iacDefaultNumber | taDefaultAsNumber) & tvrAsNumber) == 0");
                        Logger.Log("iacDefaultNumber: " + iacDefaultNumber);
                        Logger.Log("taDefaultAsNumber: " + taDefaultAsNumber);
                        int depth = 0;
                        Logger.Log(tvr.ToPrintString(ref depth));
                        return(ACTypeEnum.AAC);

                        #endregion
                    }
                }
                else
                {
                    #region taa.14
                    if (tvrAsNumber == 0)
                    #endregion
                    {
                        #region taa.15
                        return(ACTypeEnum.TC);

                        #endregion
                    }
                    else
                    {
                        #region taa.17
                        Logger.Log("Declining: tvrAsNumber == 0");
                        int depth = 0;
                        Logger.Log(tvr.ToPrintString(ref depth));
                        return(ACTypeEnum.AAC);

                        #endregion
                    }
                }
            }
            else
            {
                #region taa.7
                if (database.IsNotEmpty(EMVTagsEnum.ISSUER_ACTION_CODE_ONLINE_9F0F_KRN.Tag))
                #endregion
                {
                    ulong iacOnlineNumber   = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.ISSUER_ACTION_CODE_ONLINE_9F0F_KRN).Value);
                    ulong tacOnlineAsNumber = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.TERMINAL_ACTION_CODE_ONLINE_DF8122_KRN2).Value);
                    #region taa.10
                    if (((tacOnlineAsNumber | iacOnlineNumber) & tvrAsNumber) == 0)
                    #endregion
                    {
                        #region taa.12
                        return(ACTypeEnum.TC);

                        #endregion
                    }
                    else
                    {
                        #region taa.11
                        return(ACTypeEnum.ARQC);

                        #endregion
                    }
                }
                else
                {
                    #region taa.8
                    if (tvrAsNumber == 0)
                    #endregion
                    {
                        #region taa.9
                        return(ACTypeEnum.TC);

                        #endregion
                    }
                    else
                    {
                        #region taa.11
                        return(ACTypeEnum.ARQC);

                        #endregion
                    }
                }
            }
        }
        private static SignalsEnum EntryPointOnline(KernelDatabase database, KernelRequest kernel1Request, KernelQ qManager, CardQ cardQManager, EMVSelectApplicationResponse emvSelectApplicationResponse)
        {
            KernelOnlineRequest response = (KernelOnlineRequest)kernel1Request;

            //check if approved or not or unable to go online
            if (response.OnlineApprovalStatus == KernelOnlineResponseType.UnableToGoOnline)
            {
                //if unable to go online, check what action to take using TAC/IAC default,
                TERMINAL_VERIFICATION_RESULTS_95_KRN tvr = new TERMINAL_VERIFICATION_RESULTS_95_KRN(database);
                ulong tvrAsNumber = Formatting.ConvertToInt64(tvr.Value.Value);
                ulong tacAsNumber = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.TERMINAL_ACTION_CODE_DEFAULT_DF8120_KRN2).Value);
                if (database.IsNotEmpty(EMVTagsEnum.ISSUER_ACTION_CODE_DEFAULT_9F0D_KRN.Tag))
                {
                    ulong iacAsNumber = Formatting.ConvertToInt64(database.Get(EMVTagsEnum.ISSUER_ACTION_CODE_DEFAULT_9F0D_KRN).Value);
                    if (!(
                            ((tacAsNumber | iacAsNumber) & tvrAsNumber) == 0)
                        )
                    {
                        database.ACType.Value.DSACTypeEnum = ACTypeEnum.AAC;
                    }
                    else
                    {
                        database.ACType.Value.DSACTypeEnum = ACTypeEnum.TC;
                    }
                }
                else
                {
                    if (!((tacAsNumber & tvrAsNumber) == 0))
                    {
                        database.ACType.Value.DSACTypeEnum = ACTypeEnum.AAC;
                    }
                    else
                    {
                        database.ACType.Value.DSACTypeEnum = ACTypeEnum.TC;
                    }
                }
                //what should these be set to in this case?
                database.AddToList(TLV.Create(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag));
                database.AddToList(TLV.Create(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag));
            }
            else
            {
                if (response.OnlineApprovalStatus == KernelOnlineResponseType.Approve)
                {
                    database.ACType.Value.DSACTypeEnum = ACTypeEnum.TC;
                }
                else
                {
                    database.ACType.Value.DSACTypeEnum = ACTypeEnum.AAC;
                }
                database.AddToList(response.InputData.Get(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag));
                database.AddToList(response.InputData.Get(EMVTagsEnum.AUTHORISATION_RESPONSE_CODE_8A_KRN.Tag));
                if (response.InputData.Get(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_1_71_KRN.Tag) != null)
                {
                    database.AddToList(response.InputData.Get(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_1_71_KRN.Tag));
                }
                if (response.InputData.Get(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_2_72_KRN.Tag) != null)
                {
                    database.AddToList(response.InputData.Get(EMVTagsEnum.ISSUER_SCRIPT_TEMPLATE_2_72_KRN.Tag));
                }
            }

            APPLICATION_INTERCHANGE_PROFILE_82_KRN aip = new APPLICATION_INTERCHANGE_PROFILE_82_KRN(database);

            if (aip.Value.IssuerAuthenticationIsSupported && response.OnlineApprovalStatus != KernelOnlineResponseType.UnableToGoOnline)
            {
                TLV _91 = response.InputData.Get(EMVTagsEnum.ISSUER_AUTHENTICATION_DATA_91_KRN.Tag);
                EMVExternalAuthenticateRequest request = new EMVExternalAuthenticateRequest(_91.Value);
                cardQManager.EnqueueToInput(new CardRequest(request, CardinterfaceServiceRequestEnum.ADPU));
                return(SignalsEnum.WAITING_FOR_EXTERNAL_AUTHENTICATE);
            }
            else
            {
                //if scripts need to be run before gen ac, do now
                return(CardActionAnalysis.Initiate2ndCardActionAnalysis(database, qManager, cardQManager, emvSelectApplicationResponse));
            }
        }