<?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::table('jadwal_ujian', function (Blueprint $table) {
            // Hapus kolom lama yang tidak diperlukan
            $table->dropColumn(['nama_sesi', 'tanggal']);

            // Tambah kolom baru
            $table->string('nama')->after('tahun_ajaran_id'); // contoh: UM 2025/2026 Semester 2
            $table->date('tanggal_mulai')->after('nama');
            $table->date('tanggal_selesai')->after('tanggal_mulai');

            $table->index('tanggal_mulai');
        });
    }

    public function down(): void
    {
        Schema::table('jadwal_ujian', function (Blueprint $table) {
            $table->dropIndex(['tanggal_mulai']);
            $table->dropColumn(['nama', 'tanggal_mulai', 'tanggal_selesai']);
            $table->string('nama_sesi')->after('tahun_ajaran_id');
            $table->date('tanggal')->after('durasi_menit');
        });
    }
};
