class InterviewApplicationFeedbackServiceImpl implements InterviewApplicationFeedbackService {

    @Override
    public ServiceResult<Void> deleteFeedback(long applicationId) {
        return findAssignmentByApplicationId(applicationId).andOnSuccess(interviewAssignment -> {
            long fileId = interviewAssignment.getMessage().getFeedback().getId();
            return fileService.deleteFileIgnoreNotFound(fileId).andOnSuccessReturnVoid(() -> {
                if (interviewAssignment.getProcessState() == InterviewAssignmentState.CREATED) {
                    InterviewAssignmentMessageOutcome messageOutcome = interviewAssignment.getMessage();
                    interviewAssignment.removeMessage();
                    interviewAssignmentMessageOutcomeRepository.delete(messageOutcome);
                } else {
                    interviewAssignment.getMessage().setFeedback(null);
                }
            });
        });
    }

}