<?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
    {
        if (!Schema::hasColumn('riwayat_rekomendasis', 'akurasi_prediksi')) {
            Schema::table('riwayat_rekomendasis', function (Blueprint $table) {
                $table->decimal('akurasi_prediksi', 5, 2)
                    ->nullable()
                    ->after('hasil_rekomendasi_jurusan');
            });
        }

        if (!Schema::hasColumn('riwayat_rekomendasis', 'detail_probabilitas')) {
            Schema::table('riwayat_rekomendasis', function (Blueprint $table) {
                $table->json('detail_probabilitas')
                    ->nullable()
                    ->after('akurasi_prediksi');
            });
        }
    }

    public function down(): void
    {
        Schema::table('riwayat_rekomendasis', function (Blueprint $table) {
            if (Schema::hasColumn('riwayat_rekomendasis', 'detail_probabilitas')) {
                $table->dropColumn('detail_probabilitas');
            }

            if (Schema::hasColumn('riwayat_rekomendasis', 'akurasi_prediksi')) {
                $table->dropColumn('akurasi_prediksi');
            }
        });
    }
};