<?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('kelas', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tahun_ajaran_id')->constrained('tahun_ajaran')->cascadeOnDelete();
            $table->foreignId('tingkat_sekolah_id')->constrained('tingkat_sekolah')->cascadeOnDelete();
            $table->string('nama'); // contoh: VII-A, VIII-B
            $table->integer('tingkat'); // 1-6 (MI), 7-9 (MTs), 10-12 (MA)
            $table->integer('jumlah_siswa')->default(0);
            $table->timestamps();

            $table->index('tahun_ajaran_id');
            $table->index('tingkat_sekolah_id');
        });
    }

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