<?php

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

return new class extends Migration
{
    public function up(): void
    {
        if (!Schema::hasTable('teachers')) {
            Schema::create('teachers', function (Blueprint $table) {
                $table->integer('teacher_id')->primary();
                $table->string('user_id')->nullable();
                $table->string('name');
                $table->string('subject')->nullable();
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('students')) {
            Schema::create('students', function (Blueprint $table) {
                $table->integer('student_id')->primary();
                $table->string('name');
                $table->string('grade')->nullable();
                $table->string('class_name')->nullable();
                $table->integer('teacher_id')->nullable();
                $table->text('remark')->nullable();
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('paper_questions')) {
            Schema::create('paper_questions', function (Blueprint $table) {
                $table->id();
                $table->string('question_text')->nullable();
                $table->string('knowledge_point')->nullable();
                $table->timestamps();
            });
        }

        if (!Schema::hasTable('student_exercises')) {
            Schema::create('student_exercises', function (Blueprint $table) {
                $table->id();
                $table->integer('student_id');
                $table->string('question_text')->nullable();
                $table->string('kp_name')->nullable();
                $table->integer('difficulty')->nullable();
                $table->timestamps();
            });
        }
    }

    public function down(): void
    {
        Schema::dropIfExists('student_exercises');
        Schema::dropIfExists('paper_questions');
        Schema::dropIfExists('students');
        Schema::dropIfExists('teachers');
    }
};
