/* eslint-disable */
'use strict';

module.exports = {
  async up(queryInterface) {
    // chapter_id optional machen (nicht alle Lektionen brauchen ein Kapitel)
    await queryInterface.sequelize.query(`
      ALTER TABLE community.vocab_course_lesson
      ALTER COLUMN chapter_id DROP NOT NULL;
    `);

    // Kurs-Wochen/Module hinzufügen
    await queryInterface.sequelize.query(`
      ALTER TABLE community.vocab_course_lesson
      ADD COLUMN IF NOT EXISTS week_number INTEGER,
      ADD COLUMN IF NOT EXISTS day_number INTEGER,
      ADD COLUMN IF NOT EXISTS lesson_type TEXT DEFAULT 'vocab',
      ADD COLUMN IF NOT EXISTS audio_url TEXT,
      ADD COLUMN IF NOT EXISTS cultural_notes TEXT;
    `);

    // Indizes für Wochen/Tage
    await queryInterface.sequelize.query(`
      CREATE INDEX IF NOT EXISTS vocab_course_lesson_week_idx
        ON community.vocab_course_lesson(course_id, week_number);
      CREATE INDEX IF NOT EXISTS vocab_course_lesson_type_idx
        ON community.vocab_course_lesson(lesson_type);
    `);

    // Kommentar hinzufügen für lesson_type
    await queryInterface.sequelize.query(`
      COMMENT ON COLUMN community.vocab_course_lesson.lesson_type IS 
        'Type: vocab, grammar, conversation, culture, review';
    `);
  },

  async down(queryInterface) {
    await queryInterface.sequelize.query(`
      ALTER TABLE community.vocab_course_lesson
      DROP COLUMN IF EXISTS week_number,
      DROP COLUMN IF EXISTS day_number,
      DROP COLUMN IF EXISTS lesson_type,
      DROP COLUMN IF EXISTS audio_url,
      DROP COLUMN IF EXISTS cultural_notes;
    `);
  }
};
