#include <iostream>

#include "collect.h"


ostream & operator<<(ostream & os, const vector<string> & s) {
    os << "menu:\n";
    for(auto i: s) {
        os << "  " << i << endl;
    }
    return os;
}

garray initial_restaurants() {
    garray a;
    a.add("Cafe Rio");
    a.add("Pappa Murphy's");
    a.add("Quiznos");
    a.add("Jimmy Johns");
    a.add("Thai Chili Gardens");
    a.add("Subway");
    a.add("Taco Bell");
    a.add("India Palace");
    return a;
}

garray populate_restaurants() {
    string input;
    bool running = true;
    garray restaurants = initial_restaurants();
    while(running) {
        cout << "\n" << menu << endl;
        cout << "your selection: ";
        cin >> input;
        cout << endl;
        if(input[0] == 'd') {
            cout << restaurants << endl;
        }
        else if(input[0] == 'a') {
            cout << "which restaurant should I ADD: ";
            string name;
            cin.ignore();
            getline(cin, name);
            bool add_results = restaurants.add(name);
            if(add_results) {
                cout << "added '" << name << "' successfully!" << endl;
            }
            else {
                cerr << "did not add: '" << name << "' "
                   << "(already there or max size)" << endl;
            }
        }
        else if(input[0] == 'r') {
            cout << "which restaurant should I REMOVE: ";
            string name;
            cin.ignore();
            getline(cin, name);
            bool remove_results = restaurants.remove(name);
            if(remove_results) {
                cout << "removed '" << name << "' successfully!" << endl;
            }
            else {
                cerr << "did not remove: '" << name << "' "
                    << "(probably not in array)" << endl;
            }
        }
        else if(input[0] == 's') {
            restaurants.randomize();
        }
        else if(input[0] == 'b') {
            running = false;
        }
    }
    return restaurants;
}
