class InterviewApplicationSendInviteController {

    @PostMapping(value = "/{applicationId}/edit")
    public String resendInvite(Model model, @Valid @ModelAttribute("form") InterviewApplicationResendForm form,
                             BindingResult bindingResult,
                             ValidationHandler validationHandler,
                             @PathVariable("competitionId") long competitionId,
                             @PathVariable("applicationId") long applicationId) {
        Supplier<String> failureView = () -> editInvite(model,  form, competitionId, applicationId);
        Supplier<String> successView = () -> redirectToStatusTab(competitionId);

        return validationHandler.failNowOrSucceedWith(failureView, () -> {
            final RestResult<Void> fileResult;
            if (form.getFeedback() != null && !form.getFeedback().isEmpty()) {
                MultipartFile file = form.getFeedback();
                interviewAssignmentRestService.deleteFeedback(applicationId);
                fileResult = interviewAssignmentRestService
                        .uploadFeedback(applicationId, file.getContentType(), file.getSize(), file.getOriginalFilename(), getMultipartFileBytes(file));

            } else if (form.isRemoveFile()) {
                fileResult = interviewAssignmentRestService.deleteFeedback(applicationId);
            } else {
                fileResult = restSuccess();
            }

            return validationHandler.addAnyErrors(fileResult, fileUploadField("feedback")).failNowOrSucceedWith(failureView, () -> {
                RestResult<Void> result = interviewAssignmentRestService
                        .resendInvite(applicationId, new AssessorInviteSendResource(form.getSubject(), form.getContent()));

                return validationHandler.addAnyErrors(error(removeDuplicates(result.getErrors())))
                        .failNowOrSucceedWith(failureView, successView);
                }
            );
        });
    }

    @Autowired public  InterviewApplicationSendInviteController(InterviewApplicationsSendModelPopulator interviewApplicationsSendModelPopulator,
                                                    InterviewApplicationSentInviteModelPopulator interviewApplicationSentInviteModelPopulator,
                                                    InterviewAssignmentRestService interviewAssignmentRestService);

}