import {Stakeholder,Topic,Category,SubCategory,Indicator, IndicatorPath, ChartHelper} from "./stakeholder";

export class StakeholderCreator {

  static createFunderDefaultProfile():Stakeholder{
    let funder:Stakeholder = new Stakeholder(null,"funder","_funder_id_","_funder_name_","_FSN_",true,"deafult_funder",true,true, null);
    funder.topics.push(StakeholderCreator.createResearchProductionTopic(funder));
    funder.topics.push(StakeholderCreator.createOpenAccessTopic(funder));

    funder.topics.push(StakeholderCreator.createOSTopic(funder));
    funder.topics.push(funder.createImpactTopic());
    funder.topics.push(funder.createCollaborationTopic());
    return funder;
  }
  static createFunderFromDefaultProfile(id: string, type: string, index_id, index_name: string, index_shortName:string , isDefaultProfile: boolean, alias:string , isActive: boolean, isPublic: boolean, logoUrl:string):Stakeholder{
    let funder:Stakeholder = StakeholderCreator.createFunderDefaultProfile();
    funder.initializeFunder(id,type, index_id, index_name, index_shortName, isDefaultProfile, alias, isActive, isPublic, logoUrl);
    for (let topic of funder.topics) {
      for (let category of topic.categories) {
        let subTokeep: SubCategory[] = [];
        for (let subCategory of category.subCategories) {
          let chartsTokeep: Indicator[] = [];
          if (subCategory.recommendedFor.length == 0 || subCategory.recommendedFor.indexOf(id) != -1) {
            subTokeep.push(subCategory);
          }
          for (let indicator of subCategory.charts) {
            if (indicator.recommendedFor.length == 0 || indicator.recommendedFor.indexOf(id) != -1) {
              chartsTokeep.push(indicator);
            }
            for (let indicatorPath of indicator.indicatorPaths) {
              if (indicatorPath.parameters) {
                Object.keys(indicatorPath.parameters).forEach(key => {
                  if (indicatorPath.parameters[key].indexOf("_funder_name_") != -1) {
                    indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_name_", funder.index_name);
                  } else if (indicatorPath.parameters[key].indexOf("_fsn_") != -1) {
                    indicatorPath.parameters[key] = indicatorPath.parameters[key].toString().replace("_fsn_", funder.index_shortName.toLowerCase());
                  }
                });
              }
            }

          }
          subCategory.charts = chartsTokeep;
          for (let indicator of subCategory.numbers) {
            for (let indicatorPath of indicator.indicatorPaths) {
              indicatorPath.url = indicatorPath.url.replace("_funder_id_", funder.index_id);
              // if(indicatorPath.parameters) {
              //   indicatorPath.parameters.forEach((value: string, key: string) => {
              //     if (value.indexOf("_funder_name_")!=-1) {
              //       indicatorPath.parameters.set(key,value.toString().replace("_funder_name_", funder.index_name));
              //     }else if (value.indexOf("_fsn_")!=-1) {
              //       indicatorPath.parameters.set(key,value.toString().replace("_fsn_", funder.index_shortName.toLowerCase()));
              //     }
              //   });
              // }
            }
          }

        }
        category.subCategories = subTokeep;
      }
    }

      console.log(funder);
    return funder;
  }

  static createResearchProductionTopic(stakeholder:Stakeholder):Topic {
    let topic = new Topic("Research production", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do...", "research-production", true, true);

    let pubCategory:Category =  new Category("Publications","","publications",true,true);
    topic.categories.push(pubCategory);
    // let pubDefSub = StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications");
    pubCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications",0));
    pubCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications",1));
    pubCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Publications", "Publication","publication", "publications",2));

    let dataCategory:Category =  new Category("Research data","","data",true,true);
    topic.categories.push(dataCategory);
    dataCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Research data", "Research data","dataset", "datasets",0));
    dataCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Research data", "Research data","dataset", "datasets",1));
    dataCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Research data", "Research data","dataset", "datasets",2));

    let softwareCategory:Category =  new Category("Software","","software",true,true);
    topic.categories.push(softwareCategory);
    softwareCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Software", "Software","software", "datasets",0));
    softwareCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Software", "Software","software", "datasets",1));
    softwareCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Software", "Software","software", "datasets",2));

    let otherCategory:Category =  new Category("Other research products","","other",true,true);
    topic.categories.push(otherCategory);
    otherCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Other research products", "Other research product","other", "other",0));
    otherCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Other research products", "Other research product","other", "other",1));
    otherCategory.subCategories.push(StakeholderCreator.createResearchProductionPerType(stakeholder,"Other research products", "Other research product","other", "other",2));


    return topic;

  }
  static createResearchProductionPerType(stakeholder:Stakeholder,typePlural, typeSingl, dbType, dbTypePlural, index:number):SubCategory{

    let fundingFilter = ['',',{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["FP7"]}],"op":"AND"}',
      ',{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["H2020"]}],"op":"AND"}'];
    let categoryTitle=["Overview","FP7","H2020"];
    let chartTitle=["","FP7 ","H2020 "];
    let pubDefSub = new SubCategory(categoryTitle[index], null,categoryTitle[index].toLowerCase(),true, true);
    if(index!=0){
      pubDefSub.recommendedFor.push("ec");
    }
    if(index==0) {
      let n_total = new Indicator("Total " + typePlural, null, "number", "small", true, true, [new IndicatorPath(null, "search",
        "/" + dbTypePlural + "/count?fq=" + (encodeURIComponent("relfunderid exact " + stakeholder.index_id)) + "&format=json", null, ["total"])]);
      n_total.indicatorPaths[0].filters["fundingL0"] = "&fq=relfundinglevel0_name exact " + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix;
      pubDefSub.numbers.push(n_total);
    }
    if( dbType != "publication" && index == 0) {
      let n_linkedPubs = this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Publications","publication");

        // new Indicator("Linked with Publications", null, "number", "small", true, true, [new IndicatorPath(null, "search",
        // "/resources?query="+encodeURIComponent(" ( (oaftype exact result) and (resulttypeid exact " + dbTypePlural + ") and (relresulttype=publication)  )")+"&fq=" + (encodeURIComponent("relfunderid exact " + stakeholder.index_id)) + "&page=0&size=0&format=json", null, ["meta","total"])]);
      pubDefSub.numbers.push(n_linkedPubs);
    }

    let res_timeline = new Indicator("",null, "chart","small",true, true,[new IndicatorPath("column", "stats-tool", "chart?json=", '{"library":"HighCharts","chartDescription":{"queries":[{"name":"'+typePlural+'","type":"'+ChartHelper.prefix+'type'+ChartHelper.suffix+'","query":{"select":[{"field":"'+dbType+'","aggregate":"count"},{"field":"'+dbType+'.year","aggregate":null}],"filters":[{"groupFilters":[{"field":"'+dbType+'.project.funder","type":"=","values":["'+ChartHelper.prefix+'funder_name'+ChartHelper.suffix+'"]}],"op":"AND"},{"groupFilters":[{"field":"'+dbType+'.year","type":">=","values":["'+ChartHelper.prefix+'start_year'+ChartHelper.suffix+'"]},{"field":"'+dbType+'.year","type":"<=","values":["'+ChartHelper.prefix+'end_year'+ChartHelper.suffix+'"]}],"op":"AND"}'+fundingFilter[index]+'],"entity":"'+dbType+'","profile":"OpenAIRE All-inclusive","limit":"0"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"'+ChartHelper.prefix+'title'+ChartHelper.suffix+'"},"subtitle":{},"yAxis":{"title":{"text":"'+typePlural+'"}},"xAxis":{"title":{"text":"Year"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
    res_timeline.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,chartTitle[index] + typePlural+" timeline","column");
    res_timeline.indicatorPaths[0].parameters["start_year"] = (index == 1?"2014":"2008");
    res_timeline.indicatorPaths[0].parameters["end_year"] = "2020";
    res_timeline.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
    pubDefSub.charts.push(res_timeline);


    if(dbType == "publication" || dbType == "dataset") {

      let res_types = new Indicator("", null, "chart", "small", true, true,
        [new IndicatorPath("column", "stats-tool", "chart?json=",
          '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.classification","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'funder_name' + ChartHelper.suffix + '"]}],"op":"AND"}'+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"0"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Type"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      res_types.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " types", "bar");
      res_types.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
      pubDefSub.charts.push(res_types);
    }
    let res_access_mode = new Indicator("",null, "chart","small",true, true,[new IndicatorPath("pie", "stats-tool", "chart?json=",
      '{"library":"HighCharts","chartDescription":{"queries":[{"name":"'+typePlural+'","type":"'+ChartHelper.prefix+'type'+ChartHelper.suffix+'","query":{"select":[{"field":"'+dbType+'","aggregate":"count"},{"field":"'+dbType+'.access mode","aggregate":null}],"filters":[{"groupFilters":[{"field":"'+dbType+'.project.funder","type":"=","values":["'+ChartHelper.prefix+'funder_name'+ChartHelper.suffix+'"]}],"op":"AND"}'+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"0"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"'+ChartHelper.prefix+'title'+ChartHelper.suffix+'"},"subtitle":{},"yAxis":{"title":{"text":"'+typePlural+'"}},"xAxis":{"title":{"text":"Year"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
    res_access_mode.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,chartTitle[index] + typeSingl+" acccess mode","pie");
    res_access_mode.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
    pubDefSub.charts.push(res_access_mode);


      let res_sci_area = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'funder_name' + ChartHelper.suffix + '"]}],"op":"AND"}'+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Scientific area"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      res_sci_area.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " scientific area", "bar");
      res_sci_area.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
      res_sci_area.recommendedFor = ["ec"];
      pubDefSub.charts.push(res_sci_area);

      let res_programmes = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"select":[{"field":"' + dbType + '","aggregate":"count"},{"field":"' + dbType + '.project.funding level 2","aggregate":null}],"filters":[{"groupFilters":[{"field":"' + dbType + '.project.funder","type":"=","values":["' + ChartHelper.prefix + 'funder_name' + ChartHelper.suffix + '"]}],"op":"AND"},{"groupFilters":[{"field":"' + dbType + '.project.funding level 2","type":"!=","values":[" "]}],"op":"AND"}'+fundingFilter[index]+'],"entity":"' + dbType + '","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Programmes"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      res_programmes.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " programmes", "bar");
      res_programmes.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
    res_programmes.recommendedFor = ["ec"];
      pubDefSub.charts.push(res_programmes);

    //{"library":"HighCharts","chartDescription":{"queries":[{"name":"Research Data","type":"bar","query":{"select":[{"field":"dataset","aggregate":"count"},{"field":"dataset.project.funding level 1","aggregate":null}],"filters":[{"groupFilters":[{"field":"dataset.project.funder","type":"=","values":["European Commission"]}],"op":"AND"}],"entity":"dataset","profile":"OpenAIRE All-inclusive","limit":"30"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"Scientific Area"},"subtitle":{},"yAxis":{"title":{}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}
    let datasource = new Indicator("",null, "chart","small",true, true,[new IndicatorPath("bar", "stats-tool", "chart?json=",
      '{"library":"HighCharts","chartDescription":{"queries":[{"name":"'+typePlural+'","type":"'+ChartHelper.prefix+'type'+ChartHelper.suffix+'","query":{"name":"monitor.'+ChartHelper.prefix+'id'+ChartHelper.suffix+(index==1?".h2020":(index==2?".fp7":""))+'.'+dbTypePlural+'.datasources"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"'+ChartHelper.prefix+'title'+ChartHelper.suffix+'"},"subtitle":{},"yAxis":{"title":{"text":"'+typePlural+'"}},"xAxis":{"title":{"text":"Content provider"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
    datasource.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name,chartTitle[index] + typeSingl+" content provider","bar");
    datasource.indicatorPaths[0].parameters["id"] = stakeholder.index_shortName.toLowerCase();
    pubDefSub.charts.push(datasource);
    if(dbType == "publication") {
      let journal = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix +(index==1?".h2020":(index==2?".fp7":""))+ '.' + dbTypePlural + '.journals"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Journal"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      journal.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " journal", "bar");
      journal.indicatorPaths[0].parameters["id"] = stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts.push(journal);

      let repo = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix +(index==1?".h2020":(index==2?".fp7":""))+ '.' + dbTypePlural + '.repositories"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Repositories"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      repo.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " repositories", "bar");
      repo.indicatorPaths[0].parameters["id"] = stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts.push(repo);
    }
    if(dbType == "dataset") {
      let repo = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix + (index==1?".h2020":(index==2?".fp7":""))+'.' + dbTypePlural + '.drepositories"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Data Repositories"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      repo.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " repositories", "bar");
      repo.indicatorPaths[0].parameters["id"] =  stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts.push(repo);

      let irepo = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("bar", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix +(index==1?".h2020":(index==2?".fp7":""))+ '.' + dbTypePlural + '.irepositories"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"yAxis":{"title":{"text":"' + typePlural + '"}},"xAxis":{"title":{"text":"Institutional repositories"}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      irepo.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, chartTitle[index] + typeSingl + " institutional repositories", "bar");
      irepo.indicatorPaths[0].parameters["id"] =  stakeholder.index_shortName.toLowerCase();
      pubDefSub.charts.push(irepo);
    }

    if(index ==0) {
      let pid = new Indicator("", null, "chart", "small", true, true, [new IndicatorPath("pie", "stats-tool", "chart?json=",
        '{"library":"HighCharts","chartDescription":{"queries":[{"name":"' + typePlural + '","type":"' + ChartHelper.prefix + 'type' + ChartHelper.suffix + '","query":{"name":"monitor.' + ChartHelper.prefix + 'id' + ChartHelper.suffix + '.' + dbTypePlural + '.pidtypes"}}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":"' + ChartHelper.prefix + 'title' + ChartHelper.suffix + '"},"subtitle":{},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":true},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":true,"align":"center","verticalAlign":"bottom","layout":"horizontal"},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}', null)]);
      pid.indicatorPaths[0].parameters = IndicatorPath.createParameters(stakeholder.index_name, typeSingl + " PIDs", "pie");
      pid.indicatorPaths[0].parameters["id"] = stakeholder.index_shortName.toLowerCase();
      pid.indicatorPaths[0].filters = IndicatorPath.createResultFilters(dbType);
      pubDefSub.charts.push(pid);
    }
    return pubDefSub;
  }
  static createOASub(){
    let subCategories:SubCategory[] = [];
    let overviewSub = new SubCategory("Overview", null,"overview",true, true);
    subCategories.push(overviewSub);
    let byScientificAreaSub = new SubCategory("By Scientific Area", null,"scientific-area",true, true);
    subCategories.push(byScientificAreaSub);
    let byProgramSub = new SubCategory("By Programme", null,"programme",true, true);
    subCategories.push(byProgramSub);
    return subCategories;


  }
  static createOpenAccessTopic(stakeholder:Stakeholder):Topic {
    let topic = new Topic("Open Access", "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do...", "open-access", true, true);

    let pubCategory:Category =  new Category("Publications","","publications",true,true);
    topic.categories.push(pubCategory);
    pubCategory.subCategories = StakeholderCreator.createOASub();

    let dataCategory:Category =  new Category("Research data","","data",true,true);
    topic.categories.push(dataCategory);
    dataCategory.subCategories = StakeholderCreator.createOASub();

    let softwareCategory:Category =  new Category("Software","","software",true,true);
    topic.categories.push(softwareCategory);
    softwareCategory.subCategories = StakeholderCreator.createOASub();

    let otherCategory:Category =  new Category("Other research products","","other",true,true);
    topic.categories.push(otherCategory);

    otherCategory.subCategories = StakeholderCreator.createOASub();

    return topic;

  }
  static createOSTopic(stakeholder:Stakeholder):Topic{
    let topic = new Topic("Open Science","Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do...","open-science",true,true);

   let overview:Category =  new Category("Overview","","overview",true,true);
    topic.categories.push(overview);
    overview.subCategories.push(this.createOSOverviewPerType(stakeholder,"Publications","Publication","publication","publications"));
    overview.subCategories.push(this.createOSOverviewPerType(stakeholder,"Research data","Research data","dataset","datasets"));
    overview.subCategories.push(this.createOSOverviewPerType(stakeholder,"Software","Software","software","software"));
    overview.subCategories.push(this.createOSOverviewPerType(stakeholder,"Other research products","Other research product","other","other"));

    return topic;

  }
  static createOSOverviewPerType(stakeholder:Stakeholder,typePlural, typeSingl, dbType, dbTypePlural ):SubCategory {

    let pubDefSub = new SubCategory(typePlural, null, dbTypePlural, true, true);

    if( dbType != "publication") {
      pubDefSub.numbers.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Publications","publication"));
    }
    if( dbType != "dataset") {
      pubDefSub.numbers.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Research data","dataset"));
    }
    if( dbType != "software") {
      pubDefSub.numbers.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Software","software"));
    }
    if( dbType != "other") {
      pubDefSub.numbers.push(this.createLinkToIndicator(stakeholder,typePlural,typeSingl, dbType,"Other Research products","other"));
    }
    return pubDefSub;
  }

  static createLinkToIndicator(stakeholder:Stakeholder,typePlural, typeSingl, dbType, linkedToName,linkedToType ):Indicator {
      let n_linkedPubs = new Indicator(typePlural+" linked to "+linkedToName, null, "number", "small", true, true, [new IndicatorPath(null, "search",
        "/resources?query=" + encodeURIComponent(" ( (oaftype exact result) and (resulttypeid exact " + dbType + ") and (relresulttype="+linkedToType+")  )") + "&fq=" + (encodeURIComponent("relfunderid exact " + stakeholder.index_id)) + "&page=0&size=0&format=json", null, ["meta", "total"])]);
      n_linkedPubs.indicatorPaths[0].filters["fundingL0"] = "&fq=relfundinglevel0_name exact "+ChartHelper.prefix+'fundingL0'+ChartHelper.suffix;
      /*
    filters.set("start_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":">=","values":["'+ChartHelper.prefix+'start_year'+ChartHelper.suffix+'"]}],"op":"AND"}');
    filters.set("end_year",'{"groupFilters":[{"field":"'+dbType+'.year","type":"<=","values":["'+ChartHelper.prefix+'end_year'+ChartHelper.suffix+'"]}],"op":"AND"}');
       */
    return n_linkedPubs;
  }
  static createFundingImpactTopic():Topic{
    let topic = new Topic("Impact/Correlation","Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do...","impact",true,true);

    let pubCategory:Category =  new Category("Publications","","publications",true,true);
    topic.categories.push(pubCategory);
    let pubDefSub = new SubCategory(null, null,null,true, true);
    pubCategory.subCategories.push(pubDefSub);

    let dataCategory:Category =  new Category("Research data","","data",true,true);
    topic.categories.push(dataCategory);
    let dataDefSub = new SubCategory(null, null,null,true, true);
    dataCategory.subCategories.push(dataDefSub);

    let softwareCategory:Category =  new Category("Software","","software",true,true);
    topic.categories.push(softwareCategory);
    let softDefSub = new SubCategory(null, null,null,true, true);
    softwareCategory.subCategories.push(softDefSub);

  /*  let otherCategory:Category =  new Category("Other research products","","other",true,true);
    topic.categories.push(otherCategory);
    let otherDefSub = new SubCategory(null, null,null,true, true);
    otherCategory.subCategories.push(otherDefSub);*/


    return topic;
  }
  createCollaborationTopic():Topic{
    let topic = new Topic("Demo Topic","This is a demo topic","demo-topic",true,true);

    let category1:Category =  new Category("Category 1","This is ","cat-1",true,true);
    topic.categories.push(category1);


    let subCat1 = new SubCategory("Sub-category 1","","sub-cat-1",true,true);
    category1.subCategories.push(subCat1);


    let subCat2 = new SubCategory("Sub-category 2","","sub-cat-2",true,true);
    category1.subCategories.push(subCat2);



    let category2:Category =  new Category("Category 2 - no subcategories","","cat-2",true,true);
    topic.categories.push(category2);
    let defSub = new SubCategory(null, null,null,true, true);
    category2.subCategories.push(defSub);

    let chart1 = new Indicator(
      "Chart title goes here","Chart description goes here", "chart","medium",true, true,
      [new IndicatorPath("?", "fake","https://visme.co/blog/wp-content/uploads/2017/03/Dogs-vs-Cats-How-much-they-miss-you-relative-to-the-time-you-are-gone.png", null, null)]);
    let chart2 = new Indicator("Chart title goes here","Chart description goes here", "chart","medium",true, true, [new IndicatorPath("?", "fake","https://static.boredpanda.com/blog/wp-content/uuuploads/funny-graphs-2/funny-graphs-legs.jpg", null, null)]);
    subCat1.charts.push(chart1);
    subCat2.charts.push(chart2);

    defSub.charts.push(chart1);
    defSub.charts.push(chart2);
    return topic;
  }
}






