<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::table('schedules', function (Blueprint $table) {
            // Menambahkan kolom yang hilang
            $table->date('tanggal')->nullable()->after('class');
            $table->integer('pekan_ke')->nullable()->after('tanggal');
            $table->integer('hari')->nullable()->after('pekan_ke'); // 1=Senin, 7=Minggu
            $table->string('tipe_jadwal')->default('regular')->after('hari'); // blok / regular
            
            // Memperbaiki kolom data (jika sudah ada tapi belum nullable)
            // Jika kolom 'data' belum ada, hapus ->change()
            // Asumsi dari error sebelumnya: kolom 'data' SUDAH ADA tapi tidak ada default value.
            $table->json('data')->nullable()->change(); 
        });
    }

    public function down()
    {
        Schema::table('schedules', function (Blueprint $table) {
            $table->dropColumn(['tanggal', 'pekan_ke', 'hari', 'tipe_jadwal']);
            // $table->json('data')->nullable(false)->change(); // Kembalikan jika perlu
        });
    }
};