class ProjectDetailsController {

    @PreAuthorize("hasAnyAuthority('project_finance', 'comp_admin', 'support', 'innovation_lead', 'stakeholder', 'external_finance')")
    @SecuredBySpring(value = "VIEW_PROJECT_DETAILS", description = "Project finance, comp admin, support, innovation lead and stakeholders can view the project details")
    @GetMapping("/{projectId}/details")
    public String viewProjectDetails(@PathVariable("competitionId") final Long competitionId,
                                     @PathVariable("projectId") final Long projectId, Model model,
                                     UserResource loggedInUser,
                                     boolean isSpendProfileGenerated) {

        ProjectResource projectResource = projectService.getById(projectId);
        OrganisationResource leadOrganisationResource = projectService.getLeadOrganisation(projectId);

        CompetitionResource competitionResource = competitionRestService.getCompetitionById(competitionId).getSuccess();

        boolean locationPerPartnerRequired = competitionResource.isLocationPerPartner();

        Optional<SimpleUserResource> financeReviewer = Optional.ofNullable(projectResource.getFinanceReviewer())
                .map(id -> financeReviewerRestService.findFinanceReviewerForProject(projectId).getSuccess());

        List<PartnerOrganisationResource> partnerOrganisations = locationPerPartnerRequired?
                partnerOrganisationRestService.getProjectPartnerOrganisations(projectId).getSuccess()
                : Collections.emptyList();
        List<OrganisationResource> organisations = partnerOrganisations.stream()
                .map(p -> organisationRestService.getOrganisationById(p.getOrganisation()).getSuccess())
                .collect(Collectors.toList());

        model.addAttribute("model", new ProjectDetailsViewModel(projectResource,
                competitionId,
                competitionResource.getName(),
                loggedInUser,
                leadOrganisationResource,
                locationPerPartnerRequired,
                partnerOrganisations,
                organisations,
                financeReviewer.map(SimpleUserResource::getName).orElse(null),
                financeReviewer.map(SimpleUserResource::getEmail).orElse(null),
                isSpendProfileGenerated,
                competitionResource.isKtp()));

        return "project/detail";
    }

    public  ProjectDetailsController();
    @Autowired public  ProjectDetailsController(ProjectService projectService, CompetitionRestService competitionRestService,
                                    ProjectDetailsService projectDetailsService,
                                    PartnerOrganisationRestService partnerOrganisationRestService,
                                    OrganisationRestService organisationRestService,
                                    FinanceReviewerRestService financeReviewerRestService);

}