module.exports = $app => {
  let draft_lesson_types = [
    ['1'.padStart(15, 0), 'Vocabulary', 'vocabulary', 0, 'visible'],
    ['2'.padStart(15, 0), 'Connectives', 'connectivse', 1, 'visible'],
    ['3'.padStart(15, 0), 'Testing visible', 'testing', 3, 'visible'],
    ['4'.padStart(15, 0), 'Testing hidden', 'testing', 3, 'hidden'],
    ['5'.padStart(15, 0), 'lesson type 5', 'testing', 3, 'hidden'],
    ['6'.padStart(15, 0), '中文 6', 'testing', 3, 'hidden'],
    ['7'.padStart(15, 0), 'レッスン7 レッスン7 レッスン7', 'testing', 3, 'hidden'],
  ];
  dirtyTruncateTable('LessonsTypes');

  let lt_collection = $app.findCollectionByNameOrId('LessonsTypes');

  for (let i = 0; i < draft_lesson_types.length; i++) {
    let lesson_type = draft_lesson_types[i];

    let record = new Record(lt_collection);
    record.set('id', lesson_type[0]);
    record.set('name', lesson_type[1]);
    record.set('type', lesson_type[2]);
    record.set('pos', lesson_type[3]);
    record.set('visible', lesson_type[4]);

    $app.save(record);
  }
  console.log('seeding done');
};

const dirtyTruncateTable = COLLECTION_NAME => {
  console.log(`perform dirty method to truncate table "${COLLECTION_NAME}"`);
  const cmd_to_exec = $os.cmd('sqlite3', '/pb_data/data.db', `DELETE from ${COLLECTION_NAME};`);
  cmd_to_exec.output();
};
