#include <iostream>
#include <string>
#include <fstream>
#define MAXROSTER 700
using namespace std;

struct Player{
    string team = "";
    string name = "";
    string position = "";
    bool starter = false;   
};


int main() {
    ifstream inputFile;
    string filename;
    Player players[MAXROSTER];
    string temp;
    unsigned int count = 0;

    filename = "league_roster.csv";
    inputFile.open(filename);

    if(inputFile){
        getline(inputFile, temp); // get the header line

        while(!inputFile.eof() && count < MAXROSTER){ // keep reading until the end of the file
            temp ="";
            cout << "DEBUG: roster index " << count << "\n";

            //team
            getline(inputFile, temp, ',');
            players[count].team = temp;
            cout << "team: " << temp << endl;

            //name
            temp ="";
            getline(inputFile, temp, ',');
            players[count].name = temp;
            cout << "name: " << temp << endl;

            //position
            temp ="";
            getline(inputFile, temp, ',');
            players[count].position = temp;
            cout << "position: " << temp << endl;

            //starter
            temp ="";
            getline(inputFile, temp);
            if(temp == "1"){
                players[count].starter = true;
                cout << "starter: true\n";
            }else{
                players[count].starter = false;
                cout << "starter: false\n";
            }

            count++; // move to the next player
        } // end while loop
    }else{
        cout << "\nDEBUG: Error opening file." << endl;
        exit(-1);
    }

    count--;
    cout << "\n### DEBUG (first item) ###\n"
     << "count: " << 0 << endl
     << "team: " << players[0].team << endl
     << "name: " << players[0].name << endl
     << "position: " << players[0].position << endl
     << "starter: ";
    if(players[0].starter){
        cout << "true";
    }else{
        cout << "false";
    }
    cout << endl;

    cout << "\n### DEBUG (last item) ###\n"
     << "count: " << count << endl
     << "team: " << players[count].team << endl
     << "name: " << players[count].name << endl
     << "position: " << players[count].position << endl
     << "starter: ";
    if(players[count].starter){
        cout << "true";
    }else{
        cout << "false";
    }
    cout << endl;

    return 0;
}