/// <summary>
 /// Initializes a new instance of the <see cref="StaffRealTimeSecurityValidationHelper"/> class.
 /// </summary>
 /// <param name="context">The request context.</param>
 /// <param name="verificationType">The verification type to be performed.</param>
 /// <param name="staffId">The staff identifier.</param>
 /// <param name="channelId">The channel identifier.</param>
 /// <param name="terminalRecordId">The terminal record identifier.</param>
 /// <param name="password">The employee password.</param>
 private StaffRealTimeSecurityValidationHelper(RequestContext context, SecurityVerificationType verificationType, string staffId, long?channelId, long?terminalRecordId, string password)
 {
     this.ChannelId        = channelId;
     this.TerminalRecordId = terminalRecordId;
     this.verificationType = verificationType;
     this.password         = password;
     this.context          = context;
     this.StaffId          = staffId;
 }
            /// <summary>
            /// Creates a new instance of the <see cref="StaffRealTimeSecurityValidationHelper"/> class if not already available in the context.
            /// </summary>
            /// <param name="context">The request context.</param>
            /// <param name="verificationType">The verification type to be performed.</param>
            /// <param name="staffId">The staff identifier.</param>
            /// <param name="channelId">The channel identifier.</param>
            /// <param name="terminalRecordId">The terminal record identifier.</param>
            /// <param name="password">The employee password.</param>
            /// <returns>The staff security helper instance created.</returns>
            public static StaffRealTimeSecurityValidationHelper Create(RequestContext context, SecurityVerificationType verificationType, string staffId, long?channelId, long?terminalRecordId, string password)
            {
                ThrowIf.Null(context, "context");
                ThrowIf.NullOrWhiteSpace(staffId, "staffId");

                if (verificationType.HasFlag(SecurityVerificationType.Authentication) && string.IsNullOrWhiteSpace(password))
                {
                    throw new ArgumentException("Password must be provided if authentication is required.", "password");
                }

                if (channelId.HasValue && context.GetPrincipal() != null && !context.GetPrincipal().IsTerminalAgnostic&& !terminalRecordId.HasValue)
                {
                    throw new ArgumentException("Terminal record identifier must be provided whenever channel identifier is provider.", "terminalRecordId");
                }

                StaffRealTimeSecurityValidationHelper helper            = new StaffRealTimeSecurityValidationHelper(context, verificationType, staffId, channelId, terminalRecordId, password);
                StaffRealTimeSecurityValidationHelper helperFromContext = context.GetProperty(StaffSecurityHelperContextCacheKey) as StaffRealTimeSecurityValidationHelper;

                // within the same context, authentication and authorization validations might occur separatelly
                // to avoid the penalty of two transaction service calls, we store the result for the context
                // and check if we can use the stored result for subsequent calls within the same context
                if (helperFromContext != null)
                {
                    // if helper is available from context and is equivalent to this one (based on parameters)
                    if (AreEquivalent(helperFromContext, helper))
                    {
                        // then use cached results from the one from context
                        helper.realTimeStaffVerificationEmployee = helperFromContext.realTimeStaffVerificationEmployee;
                    }
                }
                else
                {
                    // first time staff helper is used, keep it on context
                    context.SetProperty(StaffSecurityHelperContextCacheKey, helper);
                }

                return(helper);
            }