{"size": 1564, "ext": "js", "max_stars_repo_path": "src/answerHandler.js", "max_stars_repo_name": "Supasiti/team-profile-generator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/answerHandler.js", "max_issues_repo_name": "Supasiti/team-profile-generator", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/answerHandler.js", "max_forks_repo_name": "Supasiti/team-profile-generator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.0769230769, "max_line_length": 97, "alphanum_fraction": 0.6911764706}
const Manager = require('../lib/manager');
const Engineer = require('../lib/engineer');
const Intern = require('../lib/intern');
const { writeToFile } = require('./fileWriter');
const generateContent = require('./htmlGenerator');
 
const teamMembers = [];

// capitialise the first letter  
const capitalise = (string) => {
  return string[0].toUpperCase() + string.substr(1).toLowerCase();
}

const parseManager = (answer) => {
  const {name, id, email, officeNumber} = answer;
  const manager = new Manager(capitalise(name), id, email, officeNumber);
  teamMembers.push(manager);
}

const parseEngineer = (answer) => {
  const {name, id, email, github} = answer;
  const engineer = new Engineer(capitalise(name), id, email, github);
  teamMembers.push(engineer);
}

const parseIntern = (answer) => {
  const {name, id, email, school} = answer;
  const intern = new Intern(capitalise(name), id, email, school);
  teamMembers.push(intern);
}

// handle when all the information about a team member has been collected
const handleAnswer =  (answer, role) => {
  if (role === 'manager') parseManager(answer);
  if (role === 'engineer') parseEngineer(answer);
  if (role === 'intern') parseIntern(answer);
};

// handle when the user finishes adding all their team members
const handleFinish = () => {
  console.log(`
\x1b[32mGenerating the web page....\x1b[0m`);

  const content = generateContent(teamMembers);
  writeToFile('./dist/index.html', content); // file path relative to the file that is calling it
};


module.exports = {
  handleAnswer, handleFinish
};
