public static AuthorisationCallbackDataContext ResponseMode(
     this AuthorisationCallbackDataContext context,
     string value)
 {
     context.ResponseMode = value;
     return(context);
 }
 public static AuthorisationCallbackDataContext Response(
     this AuthorisationCallbackDataContext context,
     AuthorisationCallbackPayload value)
 {
     context.Response = value;
     return(context);
 }
 public static AuthorisationCallbackDataContext Data(
     this AuthorisationCallbackDataContext context,
     AuthorisationCallbackData value)
 {
     context.Data = value;
     return(context);
 }
        public static async Task <AuthorisationCallbackDataFluentResponse> SubmitAsync(
            this AuthorisationCallbackDataContext context)
        {
            context.ArgNotNull(nameof(context));

            try
            {
                AuthorisationCallbackData authData = context.Data ?? new AuthorisationCallbackData(
                    responseMode: context.ResponseMode.ArgNotNullElseInvalidOp("ResponseMode not specified"),
                    response: context.Response.ArgNotNullElseInvalidOp("Response not specified"));

                IList <FluentResponseMessage> validationErrors = new AuthorisationCallbackDataValidator()
                                                                 .Validate(authData)
                                                                 .GetOpenBankingResponses();
                if (validationErrors.Count > 0)
                {
                    return(new AuthorisationCallbackDataFluentResponse(validationErrors));
                }

                RedirectCallbackHandler handler = new RedirectCallbackHandler(
                    apiClient: context.Context.ApiClient,
                    mapper: context.Context.EntityMapper,
                    openBankingClientRepo: context.Context.ClientProfileRepository,
                    domesticConsentRepo: context.Context.DomesticConsentRepository,
                    softwareStatementProfileService: context.Context.SoftwareStatementProfileService,
                    dbMultiEntityMethods: context.Context.DbContextService,
                    apiProfileRepo: context.Context.ApiProfileRepository);

                await handler.CreateAsync(authData);

                return(new AuthorisationCallbackDataFluentResponse(new List <FluentResponseMessage>()));
            }
            catch (AggregateException ex)
            {
                context.Context.Instrumentation.Exception(ex);

                return(new AuthorisationCallbackDataFluentResponse(ex.CreateErrorMessages()));
            }
            catch (Exception ex)
            {
                context.Context.Instrumentation.Exception(ex);

                return(new AuthorisationCallbackDataFluentResponse(new[] { ex.CreateErrorMessage() }));
            }
        }