<?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::create('daya_tampung', function (Blueprint $table) {
            $table->id();
            $table->foreignId('school_id')->constrained('schools')->onDelete('cascade');
            $table->string('tahun_ajaran', 20);
            
            // Tab 1: Rombel Saat Ini (hanya untuk SLB)
            $table->unsignedInteger('tklb_a_rombel')->default(0);
            $table->unsignedInteger('tklb_a_siswa')->default(0);
            $table->unsignedInteger('tklb_b_rombel')->default(0);
            $table->unsignedInteger('tklb_b_siswa')->default(0);
            $table->unsignedInteger('kelas_1_rombel')->default(0);
            $table->unsignedInteger('kelas_1_siswa')->default(0);
            $table->unsignedInteger('kelas_2_rombel')->default(0);
            $table->unsignedInteger('kelas_2_siswa')->default(0);
            $table->unsignedInteger('kelas_3_rombel')->default(0);
            $table->unsignedInteger('kelas_3_siswa')->default(0);
            $table->unsignedInteger('kelas_4_rombel')->default(0);
            $table->unsignedInteger('kelas_4_siswa')->default(0);
            $table->unsignedInteger('kelas_5_rombel')->default(0);
            $table->unsignedInteger('kelas_5_siswa')->default(0);
            $table->unsignedInteger('kelas_6_rombel')->default(0);
            $table->unsignedInteger('kelas_6_siswa')->default(0);
            $table->unsignedInteger('kelas_7_rombel')->default(0);
            $table->unsignedInteger('kelas_7_siswa')->default(0);
            $table->unsignedInteger('kelas_8_rombel')->default(0);
            $table->unsignedInteger('kelas_8_siswa')->default(0);
            $table->unsignedInteger('kelas_9_rombel')->default(0);
            $table->unsignedInteger('kelas_9_siswa')->default(0);
            $table->unsignedInteger('kelas_10_rombel')->default(0);
            $table->unsignedInteger('kelas_10_siswa')->default(0);
            $table->unsignedInteger('kelas_11_rombel')->default(0);
            $table->unsignedInteger('kelas_11_siswa')->default(0);
            $table->unsignedInteger('kelas_12_rombel')->default(0);
            $table->unsignedInteger('kelas_12_siswa')->default(0);
            $table->unsignedInteger('total_rombel')->default(0);
            $table->unsignedInteger('total_siswa')->default(0);
            
            // Tab 2: Rencana Rombel TA Baru
            $table->unsignedInteger('rencana_rombel_tk')->default(0);
            $table->unsignedInteger('rencana_rombel_kelas_1')->default(0);
            $table->unsignedInteger('rencana_rombel_kelas_7')->default(0);
            $table->unsignedInteger('rencana_rombel_kelas_10')->default(0);
            
            // Tab 3: Daya Tampung (untuk SLB)
            $table->unsignedInteger('siswa_per_rombel')->nullable();
            $table->unsignedInteger('daya_tampung_tk')->default(0);
            $table->unsignedInteger('daya_tampung_kelas_1')->default(0);
            $table->unsignedInteger('daya_tampung_kelas_7')->default(0);
            $table->unsignedInteger('daya_tampung_kelas_10')->default(0);
            
            $table->timestamps();
            
            // Index untuk pencarian
            $table->index(['school_id', 'tahun_ajaran']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('daya_tampung');
    }
};
