#include <nlohmann/json.hpp>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>

using nlohmann::json;
using std::string;

int main() {
   std::ifstream f1("cards/template.json");
   json data = json::parse(f1);

   std::ifstream f2("cards/traits.json");
   json traits = json::parse(f2);
   

   std::ifstream f3("cards/factions.json");
   json factions = json::parse(f3);

   std::ifstream f4("cards/lines.json");
   json lines = json::parse(f4);

   std::cout << "Name: ";
   string name; std::cin >> name; data["name"] = name;

   std::cout << "Display name: ";
   std::cin.ignore();
   string display; std::getline(std::cin, display); data["display"] = display;

   std::cout << "Faction (0:Universal,1:SK,2:M,3:N,4:S): ";
   int faction; std::cin >> faction; data["faction"] = factions[faction];

   std::cout << "Line (0:front, 1:middle, 2:back): ";
   int line; std::cin >> line; data["line"] = lines[line];

   std::cout << "Power: ";
   int power; std::cin >> power; data["power"] = power;

   std::cout << "Traits (0:End,1:Spy,2:Double,3:Boost,4:Call-to-arms,5:Horn,6:Revive,7:Destroy): ";
   int trait = -1;
   while(trait != 0) {
      if(trait != -1) data["traits"].push_back(traits[trait-1]);
      std::cin >> trait;
   }

   std::ofstream out("cards/"+string(factions[faction])+"/"+name+".json");

   out << data.dump(2) << std::endl;
   return 0;
}
