package org.innovateuk.ifs.management.competition.previous.viewmodel;

import org.innovateuk.ifs.application.resource.PreviousApplicationResource;
import org.innovateuk.ifs.competition.resource.CompetitionCompletionStage;
import org.innovateuk.ifs.competition.resource.CompetitionResource;
import org.innovateuk.ifs.internal.InternalProjectSetupRow;
import org.innovateuk.ifs.status.viewmodel.BaseCompetitionStatusTableViewModel;

import java.time.ZonedDateTime;
import java.util.List;

import static org.innovateuk.ifs.util.TimeZoneUtil.toUkTimeZone;

public class PreviousCompetitionViewModel extends BaseCompetitionStatusTableViewModel {

    private final String competitionType;
    private final String fundingBody;
    private final ZonedDateTime applicationDeadline;
    private final String innovationSector;
    private final boolean competitionCanHaveProjects;
    private final List<PreviousApplicationResource> applications;

    public PreviousCompetitionViewModel(CompetitionResource competition,
                                        List<PreviousApplicationResource> applications,
                                        List<InternalProjectSetupRow> rows,
                                        boolean hasProjectFinanceRole,
                                        boolean ifsAdmin,
                                        boolean externalFinanceUser) {
        super(competition, rows, hasProjectFinanceRole, externalFinanceUser, ifsAdmin);
        this.competitionType = competition.getCompetitionTypeName();
        this.fundingBody = "Innovate UK";
        this.applicationDeadline = toUkTimeZone(competition.getEndDate());
        this.innovationSector = competition.getInnovationSectorName();
        this.competitionCanHaveProjects = CompetitionCompletionStage.PROJECT_SETUP.equals(competition.getCompletionStage());
        this.applications = applications;
    }

    @Override
    public String getEmptyTableText() {
        return "There are currently no completed projects in this competition.";
    }

    public String getCompetitionType() {
        return competitionType;
    }

    public String getFundingBody() {
        return fundingBody;
    }

    public ZonedDateTime getApplicationDeadline() {
        return applicationDeadline;
    }

    public String getInnovationSector() {
        return innovationSector;
    }

    public List<PreviousApplicationResource> getApplications() {
        return applications;
    }

    public boolean isCompetitionCanHaveProjects() {
        return competitionCanHaveProjects;
    }
}

@@ -343,16 +343,78 @@
 tupRow;%0A
+import org.innovateuk.ifs.project.internal.ProjectSetupStage;%0A
 import o
@@ -481,24 +481,24 @@
 eViewModel;%0A
-
 %0Aimport java
@@ -992,16 +992,99 @@
 cations;
+%0A    private int columnsBeforeBankDetails;%0A    private int columnsAfterBankDetails;
 %0A%0A    pu
@@ -2017,32 +2017,370 @@
  = applications;
+%0A%0A        resolveBankDetailsTableColumns();%0A    %7D%0A%0A    private void resolveBankDetailsTableColumns() %7B%0A        int bankDetailsIndex = this.getColumns().indexOf(ProjectSetupStage.BANK_DETAILS) + 1;%0A        this.columnsBeforeBankDetails = bankDetailsIndex;%0A        this.columnsAfterBankDetails = this.getColumns().size() - bankDetailsIndex;
 %0A    %7D%0A%0A    @Ove
@@ -2991,24 +2991,24 @@
 rojects() %7B%0A
-
         retu
@@ -3043,11 +3043,199 @@
 s;%0A    %7D
+%0A%0A    public int getColumnsBeforeBankDetails() %7B%0A        return columnsBeforeBankDetails;%0A    %7D%0A%0A    public int getColumnsAfterBankDetails() %7B%0A        return columnsAfterBankDetails;%0A    %7D
 %0A%7D%0A

Fix previous project view model