class ProjectPartnerInviteServiceImpl extends BaseTransactionalService implements ProjectPartnerInviteService {

    @Override
    @Transactional
    public ServiceResult<Void> invitePartnerOrganisation(long projectId, SendProjectPartnerInviteResource invite) {
        return find(projectRepository.findById(projectId), notFoundError(Project.class, projectId)).andOnSuccess(project ->
                projectInviteValidator.validate(projectId, invite).andOnSuccess(() -> {
                    InviteOrganisation inviteOrganisation = new InviteOrganisation();
                    inviteOrganisation.setOrganisationName(invite.getOrganisationName());
                    inviteOrganisation = inviteOrganisationRepository.save(inviteOrganisation);

                    ProjectPartnerInvite projectPartnerInvite = new ProjectPartnerInvite();
                    projectPartnerInvite.setInviteOrganisation(inviteOrganisation);
                    projectPartnerInvite.setEmail(invite.getEmail());
                    projectPartnerInvite.setName(invite.getUserName());
                    projectPartnerInvite.setHash(generateInviteHash());
                    projectPartnerInvite.setTarget(project);

                    projectPartnerInvite = projectPartnerInviteRepository.save(projectPartnerInvite);
                    return sendInviteNotification(projectPartnerInvite)
                            .andOnSuccessReturnVoid((sentInvite) -> sentInvite.send(loggedInUserSupplier.get(), ZonedDateTime.now()));
                })
        );
    }

}