package org.innovateuk.ifs.competitionsetup.applicationformbuilder.fundingtype;

import org.innovateuk.ifs.competition.domain.Competition;
import org.innovateuk.ifs.competition.publiccontent.resource.FundingType;
import org.innovateuk.ifs.competition.resource.CompetitionTypeEnum;
import org.innovateuk.ifs.competitionsetup.applicationformbuilder.CommonBuilders;
import org.innovateuk.ifs.finance.resource.cost.FinanceRowType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static org.innovateuk.ifs.finance.resource.cost.FinanceRowType.*;
import static org.innovateuk.ifs.finance.resource.cost.FinanceRowType.YOUR_FINANCE;

@Component
public class ThirdPartyTemplate implements FundingTypeTemplate {

    @Value("${ifs.thirdparty.ofgem.enabled}")
    private boolean thirdPartyOfgemEnabled;

    @Autowired
    private CommonBuilders commonBuilders;

    @Override
    public FundingType type() {
        return FundingType.THIRDPARTY;
    }

    @Override
    public Competition setGolTemplate(Competition competition) {
        return commonBuilders.getGolTemplate(competition);
    }

    @Override
    public Competition initialiseFinanceTypes(Competition competition) {
        List<FinanceRowType> types =
                newArrayList(
                        LABOUR,
                        MATERIALS,
                        SUBCONTRACTING_COSTS,
                        TRAVEL,
                        OTHER_COSTS,
                        OTHER_FUNDING,
                        YOUR_FINANCE);
        types.add((thirdPartyOfgemEnabled && competition.getCompetitionType().getCompetitionTypeEnum() == CompetitionTypeEnum.OFGEM) ? GRANT_CLAIM_AMOUNT : FINANCE);
        return commonBuilders.saveFinanceRows(competition, types);
    }

}


@@ -487,67 +487,8 @@
 ed;%0A
-import org.springframework.beans.factory.annotation.Value;%0A
 impo
@@ -856,99 +856,8 @@
  %7B%0A%0A
-    @Value(%22$%7Bifs.thirdparty.ofgem.enabled%7D%22)%0A    private boolean thirdPartyOfgemEnabled;%0A%0A
     
@@ -1584,35 +1584,8 @@
 add(
-(thirdPartyOfgemEnabled && 
 comp
@@ -1666,17 +1666,16 @@
 um.OFGEM
-)
  ? GRANT

remove ofgem feature toggle