#include "Graph.h"
#include <iostream>
#include <fstream>
#include <iomanip>

using std::cout;
using std::cerr;
using std::ifstream;
using std::endl;

void dijkstra(Graph *g) {
  double dist[g->vertices.size()];
  int pred[g->vertices.size()];
  
  // create heap
  // add each vertex to the heap with infinite priority and the source with 0 priority
  
  // while heap is not empty
  //   remove the min off the heap
  //   get the Vertex that is the min (depends on what you put on the heap)
  //   for each edge that is connected to the min Vertex
  //    if the distance from min Vertex along the edge is less than dist[target]
  //     update the dist array for the target Vertex
  //     update the pred array for the target Vertex
  
}


// first read in the file arg[1] as a Graph
int main(int argc, char **argv) {
  if (argc > 1) {
    ifstream inFile(argv[1]);
    if (!inFile) {
      cerr << "File could not be opened" << endl;
      exit(1);
    }
    
    Graph graph();
    
    bool edges = false;
    while (!inFile.eof()) {
      //test for each line if it has #
      if (inFile.peek() == '#') {
        // skip line
//        ifstream.ignore(1024,'\n');
        cout << "now reading edges" << endl;
        edges = true;
      }
      else if (edges) {
        // Edge
        int id1;
        int id2;

        inFile >> id1 >> id2;
        
        cout << id1 << ',' << id2 << endl;
        
        // we need to find the Vertex object that was created earlier
        Vertex* v1;
        Vertex* v2;
        // find them by iterating through our graph
        for (list<Vertex*>::iterator iter = g.vertices.begin(); 
             iter != g.vertices.end(); iter++) {
          Vertex* vTest = *iter;
          if (vTest->id == id1) {
            v1 = vTest;
          }
          else if (vTest->id == id2) {
            v2 = vTest;
          }
        }
        
        Edge *e = new Edge();
        
      }
      else {
        // Vertex
        int id;
        double x;
        double y;
        
        inFile >> id >> x >> y;
        
        cout << id << ',' << x << ',' << y << endl;
        
        Vertex* v = new Vertex(id,x,y);
        g.push_back(v);
      }
      inFile.ignore(1024,'\n');
    }
  }
}
