<?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) {
            $table->boolean('is_free')->default(false)->after('is_required');
            $table->string('video_url')->nullable()->after('is_free');
            $table->json('attachments')->nullable()->after('video_url');
            $table->json('learning_objectives')->nullable()->after('attachments');
            $table->json('tags')->nullable()->after('learning_objectives');
            $table->json('questions')->nullable()->after('tags');
            $table->integer('passing_score')->nullable()->after('questions');
            $table->integer('max_score')->nullable()->after('passing_score');
            $table->dateTime('deadline')->nullable()->after('max_score');
            $table->string('assignment_video_url')->nullable()->after('deadline');
            $table->json('assignment_learning_objectives')->nullable()->after('assignment_video_url');
            $table->json('assignment_tags')->nullable()->after('assignment_learning_objectives');
            $table->json('assignment_attachments')->nullable()->after('assignment_tags');
        });

        Schema::table('lms_course_competencies', function (Blueprint $table) {
            $table->json('sub_competencies')->nullable()->after('description');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('lms_course_lessons', function (Blueprint $table) {
            $table->dropColumn([
                'is_free',
                'video_url',
                'attachments',
                'learning_objectives',
                'tags',
                'questions',
                'passing_score',
                'max_score',
                'deadline',
                'assignment_video_url',
                'assignment_learning_objectives',
                'assignment_tags',
                'assignment_attachments',
            ]);
        });

        Schema::table('lms_course_competencies', function (Blueprint $table) {
            $table->dropColumn('sub_competencies');
        });
    }
};
