<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('lms_course_lessons', function (Blueprint $table) {
            // Add flashcards column to store flashcard data as JSON
            $table->json('flashcards')->nullable()->after('assignment_time_limit');
        });

        // Update the type enum to include 'flashcard'
        DB::statement("ALTER TABLE lms_course_lessons MODIFY COLUMN type ENUM('lesson', 'quiz', 'assignment', 'flashcard') DEFAULT 'lesson'");
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('lms_course_lessons', function (Blueprint $table) {
            $table->dropColumn('flashcards');
        });

        // Revert the type enum to original values
        DB::statement("ALTER TABLE lms_course_lessons MODIFY COLUMN type ENUM('lesson', 'quiz', 'assignment') DEFAULT 'lesson'");
    }
};
