'use strict';

const path = require('path');

const tools = require('../../tools');


// TODO DEPRECATE - check PMO Mobile, the main user of this (active)
module.exports.injectCsdrSkeletonSources = (project) => {

  tools.logInfo(`Injecting CSDR skeleton sources for : ${project.name}`);

  return Promise.resolve()
    .then(() => {
      // copying skeleton sources
      tools.copydir(path.join(__dirname, 'app-sources'), project.folder, false);

      // renaming tst.ts as it's conflicting with Jest... (TODO)
      tools.move(path.join(project.folder, 'src', 'tst.ts'), path.join(project.folder, 'src', 'test.ts'));
    })

    .catch((e) => {
      throw e;
    })

}


// TODO DEPRECATE !
module.exports.injectCsdrSkeletonEuiShowcaseSources = (project) => {

  tools.logInfo(`Injecting CSDR eUI showcase skeleton sources for : ${project.name}`);

  return Promise.resolve()
    .then(() => {
      // copying skeleton sources
      tools.copydir(path.join(__dirname, 'app-sources-eui-showcase'), project.folder, false);

      // renaming tst.ts as it's conflicting with Jest... (TODO)
      tools.move(path.join(project.folder, 'src', 'tst.ts'), path.join(project.folder, 'src', 'test.ts'));
    })

    .catch((e) => {
      throw e;
    })

}

// THIS INJECTION MAINLY USED FOR SHOWCASES
module.exports.injectCsdrFullSkeletonSources = (project, euiVersion) => {

  tools.logInfo(`Injecting CSDR full skeleton sources for : ${project.name} - eUI version : ${euiVersion}`);

  return Promise.resolve()
    .then(() => {
      tools.rimraf(path.join(project.folder, 'src', '_generated'));
    })
    .then(() => {
      // copying skeleton sources
      if (euiVersion === '13.x') {
        tools.copydir(path.join(__dirname, 'app-sources-full-skeleton-eui13'), project.folder, false);
        tools.move(path.join(project.folder, 'src', '_generated', 'tst.ts'), path.join(project.folder, 'src', '_generated', 'test.ts'));

      } else if (euiVersion === '14.x' || euiVersion === '15.x' || euiVersion === '16.x') {
        tools.copydir(path.join(__dirname, 'app-sources-full-skeleton-eui14'), project.folder, false);
        tools.move(path.join(project.folder, 'src', '_generated', 'tst.ts'), path.join(project.folder, 'src', '_generated', 'test.ts'));

      } else if (euiVersion === '17.x') {
        tools.copydir(path.join(__dirname, 'app-sources-full-skeleton-eui17'), project.folder, false);

      } else if (euiVersion === '18.x') {
        tools.copydir(path.join(__dirname, 'app-sources-full-skeleton-eui18'), project.folder, false);

      } else if (euiVersion === '19.x') {
        tools.copydir(path.join(__dirname, 'app-sources-full-skeleton-eui19'), project.folder, false);

      } else {
        tools.copydir(path.join(__dirname, 'app-sources-full-skeleton'), project.folder, false);
        tools.move(path.join(project.folder, 'src', '_generated', 'tst.ts'), path.join(project.folder, 'src', '_generated', 'test.ts'));
      }
    })

    .catch((e) => {
      throw e;
    })

}
