import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.ArrayList;
import java.util.Scanner;
import java.lang.Math;

/**
 * The MatchupReader class contains code to read lines from a file, where
 * every line contains (participant name, integer score) information for
 * two participants.
 * 
 * @author Alyce Brady
 * @version 12 December 2025
 */
public class MatchupReader 
{

    /** Constructs an object that that will read in match scores
     * from a file, two participants per line.
     */
    public MatchupReader()
    {
    }

    /** Reads in participant scores from a file (two participants per line).
     *    @param filename  the name of the file containing participant scores
     *    @param participants list of participants
     *    @return list of match-ups with scores
     *    @throws IOException if the file could not be read or contains
     *                        invalid data
     */
    public K_SimpleAL<Matchup> readScores(String fileName,
                            K_SimpleList<ParticipantInfo> participants)
            throws IOException
    {
        int lineNumber = 0;
        K_SimpleAL<Matchup> allResults = new K_SimpleAL<>();

        // YOU NEED TO ADD CODE HERE!
        // STUB CODE SO THAT IT COMPILES; replace with real code.
        return allResults;
    }

    /** Parses two participants in a line of input.
     *    @param line a line of input
     *    @param lineNumber the line number for error reporting
     *    @param participants list of participants
     *    @param allResults list of match-ups with scores to add to
     *    @throws IOException if the file could not be read or contains
     *                        invalid data
     */
    private void parseLine(String line, int lineNumber,
                           K_SimpleList<ParticipantInfo> participants,
                           K_SimpleList<Matchup> allResults)
            throws IOException
    {
        try (Scanner sc = new Scanner(line))
        {
            // Use commas as delimeters to separate names and values.  Any
            // spaces before or after the comma are considered part of the
            // delimiter, not part of the name or value being read in.
            sc.useDelimiter("\\s*,\\s*");

            while ( sc.hasNext() )
            {

                // YOU NEED TO ADD CODE HERE!

            }
        }
        catch (NoSuchElementException e)
        {
            // CREATE A NEW EXCEPTION with more information
            // AND chaining the original exception 'e' as the CAUSE.
            String newMessage = "Line " + lineNumber +
                                " does not have two (name, value) pairs.";
            throw new IOException(newMessage, e); // <-- EXCEPTION CHAINING
        }
    }

}
