class InterviewAllocationController extends CompetitionManagementCookieController<InterviewAllocationSelectionForm> {

    @PostMapping("/allocate-applications/{userId}")
    public String notifyAssessor(Model model,
                                 @ModelAttribute(name = "form") InterviewAllocationNotifyForm form,
                                 @PathVariable("competitionId") long competitionId,
                                 @PathVariable("userId") long userId,
                                 ValidationHandler validationHandler,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        Supplier<String> failureView = () -> allocateApplications(model, form, competitionId, userId, request);

        Supplier<String> successView = () -> {
            removeCookie(response, combineIds(competitionId, userId));
            return redirectToAllocatedTab(competitionId, userId);
        };

        return ifSelectionFormIsNotEmpty(competitionId, userId, request, selectionForm ->
            validationHandler
                .failNowOrSucceedWith(
                        failureView,
                        () -> {
                            RestResult<Void> sendResult =
                                    interviewAllocationRestService.notifyAllocations(
                                            new InterviewNotifyAllocationResource(
                                                    competitionId,
                                                    userId,
                                                    form.getSubject(),
                                                    form.getContent(),
                                                    selectionForm.getSelectedIds()
                                            )
                                    );
                            return validationHandler
                                    .addAnyErrors(error(removeDuplicates(sendResult.getErrors())))
                                    .failNowOrSucceedWith(
                                            failureView,
                                            successView
                                    );
                        }
                )
        );
    }

}