'use strict';

module.exports.start = () => {
  const tools = require('../../utils/tools');

  tools.logWarning('WARNING: discontinued, follow documentation for installing PROJECT + packages from "npm run init" command');

  throw new Error('DISCONTINUED');
};

// module.exports.start = () => {
//   const configUtils = require('../config/co³nfig-utils');
//   const inquirer = require('inquirer');
//   const csdrProjects = configUtils.projects.getCsdrProjects();

//   tools.logTitle('Project & team selection');

//   const startPrompt = async () => {
//     try {
//       const answersProject = await inquirer.prompt({
//         type: "list",
//         name: "project",
//         message: "Which app / project do you work on?",
//         choices: csdrProjects.filter((p) => {
//           return p.initListVisible === true;
//         }).map(p => ({ name: p.name, value: p.name }))
//       });

//       const answersTeam = await inquirer.prompt({
//         type: "list",
//         name: "team",
//         message: "Which team do you work in?",
//         choices: configUtils.projects.getTeamsProject(csdrProjects, answersProject.project)
//           .map(t => ({ name: getLabelTeam(t), value: t }))
//           .sort((a, b) => a.name > b.name ? 1 : a.name < b.name ? -1 : 0)
//           .concat([{ name: '* Install all packages', value: 'all' }])
//       });

//       const project = answersProject.project;
//       const team = answersTeam.team;

//       return { project, team };

//     } catch (e) {
//       throw e;
//     }
//   };

//   return Promise.resolve()
//     .then(() => {
//       return startPrompt();
//     })
//     .then((response) => {
//       tools.logTitle('Validating selection...');

//       if (!response.project) {
//         throw Error('Project is NOT DEFINED');
//       }

//       if (response.team) {
//         tools.logInfo(`Project: ${response.project}`);
//         tools.logInfo(`Team: ${response.team}`);
//       } else {
//         tools.logInfo(`Project: ${response.project}`);
//       }

//       const { valid, message } = validateProjectAndTeam(csdrProjects, response.project, response.team);

//       if (!valid) {
//         throw Error(`Error: ${message ? message : 'The project or team provided does not exist.'}`);
//       }

//       tools.logSuccess();

//       return response;
//     })
//     .catch((e) => {
//       throw e;
//     })
// }

// const getLabelTeam = (team) => {
//   const groups = ['track1', 'track2', 'track3'];

//   if (groups.indexOf(team) >= 0) {
//     return `Install all packages of "${team}"`;
//   }
//   return team;
// };

// const validateProjectAndTeam = (projects, project, team) => {
//   let valid = false;
//   let message;

//   projects.forEach((p) => {
//     if (p.name === project) {
//       if (!p.teams) {
//         valid = true;
//         return;
//       }

//       if (!team) {
//         message = `You need to provide a team for project "${project}"`;
//       }

//       if (p.teams.indexOf(team) >= 0 || team === 'all') {
//         valid = true;
//       }
//     }
//   });

//   return { valid, message };
// };
