<?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
    {
        Schema::create('qualifications', function (Blueprint $table) {
            $table->id();
            $table->foreignId('applicant_id')->constrained()->cascadeOnDelete();
            $table->string('qualification_type', 40)->index();
            $table->string('institution');
            $table->string('award')->nullable();
            $table->unsignedSmallInteger('year');
            $table->string('index_number', 60)->nullable();
            $table->decimal('gpa', 4, 2)->nullable();
            $table->unsignedSmallInteger('total_points')->nullable();
            $table->timestamps();
        });

        Schema::create('qualification_subjects', function (Blueprint $table) {
            $table->id();
            $table->foreignId('qualification_id')->constrained()->cascadeOnDelete();
            $table->string('subject', 120);
            $table->string('grade', 10);
            $table->unsignedSmallInteger('points')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('qualification_subjects');
        Schema::dropIfExists('qualifications');
    }
};
