public MergeOrganisationsController(IApiClient apiClient, IMergeOrganisationSessionService sessionService, IHttpContextAccessor httpContextAccessor, ILogger <MergeOrganisationsController> logger)
 {
     _apiClient           = apiClient;
     _mergeSessionService = sessionService;
     _contextAccessor     = httpContextAccessor;
     _logger = logger;
 }
        public ConfirmEpaoViewModelValidator(IMergeOrganisationSessionService mergeSessionService, IApiClient apiClient)
        {
            _mergeSessionService = mergeSessionService;
            _apiClient           = apiClient;

            RuleFor(vm => vm).Custom((vm, context) =>
            {
                var mergeRequest = _mergeSessionService.GetMergeRequest();

                if (vm.MergeOrganisationType == "primary")
                {
                    var secondaryEpao = mergeRequest.SecondaryEpao;

                    if (secondaryEpao?.Id == vm.EpaoId)
                    {
                        context.AddFailure("Epao", "The primary EPAO cannot be the same as the secondary EPAO.");
                    }
                }
                else if (vm.MergeOrganisationType == "secondary")
                {
                    var primaryEpao = mergeRequest.PrimaryEpao;

                    if (primaryEpao?.Id == vm.EpaoId)
                    {
                        context.AddFailure("Epao", "The secondary EPAO cannot be the same as the primary EPAO.");
                    }

                    var secondaryEpaoPreviousMerges = _apiClient.GetMergeLog(new GetMergeLogRequest {
                        SecondaryEPAOId = vm.EpaoId
                    }).Result;

                    if (secondaryEpaoPreviousMerges != null && secondaryEpaoPreviousMerges.Items.Count > 0)
                    {
                        context.AddFailure("Epao", "Secondary EPAO has previously been merged.");
                    }
                }
            });
        }