<?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
    {
        // 1. Tambah kolom skala_penilaian di tabel penilaians
        Schema::table('penilaians', function (Blueprint $table) {
            // Cek dulu biar tidak error jika dijalankan ulang
            if (!Schema::hasColumn('penilaians', 'skala_penilaian')) {
                $table->enum('skala_penilaian', ['angka', 'huruf'])->default('angka')->after('jenis_penilaian');
            }
        });

        // 2. Ubah kolom nilai di tabel detail agar bisa simpan huruf
        Schema::table('penilaian_details', function (Blueprint $table) {
            $table->string('nilai', 10)->change(); 
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('penilaians', function (Blueprint $table) {
            $table->dropColumn('skala_penilaian');
        });

        Schema::table('penilaian_details', function (Blueprint $table) {
            $table->integer('nilai')->change(); 
        });
    }
};