<?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
    {
        if (Schema::hasTable('student_exercises')) {
            Schema::table('student_exercises', function (Blueprint $table) {
                // 重命名字段使其与代码逻辑一致
                $table->renameColumn('question_text', 'question_content');
                $table->renameColumn('kp_name', 'kp_code');
                $table->renameColumn('difficulty', 'difficulty_level');

                // 添加 question_id 字段
                $table->string('question_id', 64)->nullable()->after('student_id');
            });
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (Schema::hasTable('student_exercises')) {
            Schema::table('student_exercises', function (Blueprint $table) {
                $table->renameColumn('question_content', 'question_text');
                $table->renameColumn('kp_code', 'kp_name');
                $table->renameColumn('difficulty_level', 'difficulty');

                // 删除 question_id 字段
                $table->dropColumn('question_id');
            });
        }
    }
};
