package com.grayben.riskExtractor.htmlScorer.partScorers.elementScorers;

import com.grayben.riskExtractor.htmlScorer.partScorers.Scorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.TagAndAttribute;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.TagAndAttributeScorer;
import com.grayben.riskExtractor.htmlScorer.partScorers.tagScorers.TagEmphasisScorer;
import org.jsoup.nodes.Element;

import java.util.ArrayList;
import java.util.List;

/**
 * Score the emphasis of an {@link org.jsoup.nodes.Element} based upon the Tag and Attributes it contains.
 */
public class EmphasisElementScorer extends Scorer<Element> {

	public final static String SCORE_LABEL = "element-emphasis";
	
	TagEmphasisScorer tagEmphasisScorer;
	TagAndAttributeScorer comboScorer;

	//TODO: test init conditions
    public EmphasisElementScorer(
            TagEmphasisScorer tagEmphasisScorer,
            TagAndAttributeScorer tagAndAttributeScorer) {
		super(SCORE_LABEL);
        this.tagEmphasisScorer = tagEmphasisScorer;
        this.comboScorer = tagAndAttributeScorer;
	}

	@Override
	public int score(Element input) {
        List<Integer> subScores = new ArrayList<>();
        validateScoreInput(input);
        subScores.add(tagEmphasisScorer.score(input.tag()));

        List<TagAndAttribute> tagAndAttributes
                = TagAndAttribute.fromElement(input);
        for (TagAndAttribute item :
                tagAndAttributes) {
            subScores.add(comboScorer.score(item));
        }

        return 0;
	}

    private void validateScoreInput(Element input){
        if (input == null){
            throw new NullPointerException(
                    "The input cannot be null"
            );
        }
    }
}

@@ -441,16 +441,46 @@
 ayList;%0A
+import java.util.Collections;%0A
 import j
@@ -1555,19 +1555,93 @@
     
-return 0;%0A%09
+Collections.sort(subScores);%0A        return subScores.get(subScores.size() - 1);%0A    
 %7D%0A%0A 

Complete score()