package app;

import diving.*;
import java.io.*;
import java.util.*;
import scoring.*;

/**
 * An application that can be used to read score information 
 * for a particular competition/event from one or more .div files,
 * each of which contains Dive information for one competitor.
 * 
 * @author Annie Pro Grammer, perspecTV
 * @version H4
 */
public class PeopleScorer
{
  /**
   * The entry point of the application.
   * 
   * @param args The command line arguments (i.e., the names of the .div files)
   * @throws FileNotFoundException If a file can't be found
   * @throws IOException If there is a problem reading a file
   * @throws SizeException If the ScoringSystem detects a problem
   */
  public static void main(final String[] args) 
      throws FileNotFoundException, IOException, SizeException
  {
    for (int i=0; i<args.length; i++)
    {
      BufferedReader in = new BufferedReader(new FileReader(args[i]));
      DiversList diversList = DivFileReader.readDiversList(in);

      System.out.println(diversList.getName());
      List<Dive> dives = diversList.getDives();
      List<Score> rawScores = new ArrayList<Score>();
      for (Dive dive: dives)
      {
        Rule rule = dive.getRule();
        ScoringSystem system = dive.getSystem();
        Score raw = system.calculate(dive.getKey(), rule.apply(dive.getScores()));
        rawScores.add(raw);
        System.out.println(raw.toString(true));
      }
      Score total = diversList.getSystem().calculate("Score", rawScores);
      System.out.println(total.toString(true));
      System.out.println("\n");
    }
  }
}
