// TODO: no leak to customer
const fs = require('fs');

const path = require('path');

const scriptPath = __filename;
const scriptDirectory = path.dirname(scriptPath);

const PROJ_HOME = path.join(scriptDirectory, '..');
const PUB_DATA = path.join(PROJ_HOME, 'public', 'data');

let quiz_content = genDummyContent(['Quiz1', 'Quiz2', 'Quiz3', 'Quiz4', 'Quiz5', 'Quiz6']);

fs.writeFileSync(
  path.join(PUB_DATA, 'Quiz', 'ConnectivesRevision', 'content.json'),
  JSON.stringify(quiz_content, null, 2)
);

function genDummyContent(item_list) {
  return item_list.map(cat_name => {
    let content = [];

    let sample_word = genSampleWord;
    let n = Math.floor(Math.random() * (10 - 3 + 1)) + 3;
    for (let i = 1; i < n; i++) {
      content.push({ ...sample_word(i, cat_name) });
    }

    return {
      cat_name,
      cat_image: 'https://docs-demo.ionic.io/assets/madison.jpg',
      content
    };
  });
}

function genSampleWord(i, cat_name) {
  i = Math.max(i, 1);
  return {
    question_fh: i + '. he like apples',
    question_sh: 'not grasps',
    modal_ans: 'but'
  };
}
