<?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('obat_masuks', function (Blueprint $table) {
            $table->string('nama_obat', 200)->after('id');
            $table->foreignId('kategori_id')->nullable()->after('nama_obat')->constrained('kategoris')->nullOnDelete();
            $table->foreignId('satuan_id')->nullable()->after('kategori_id')->constrained('satuans')->nullOnDelete();
            
            // Make obat_id nullable as we're using direct input now
            $table->foreignId('obat_id')->nullable()->change();
        });
    }

    public function down(): void
    {
        Schema::table('obat_masuks', function (Blueprint $table) {
            $table->dropForeign(['kategori_id']);
            $table->dropForeign(['satuan_id']);
            $table->dropColumn(['nama_obat', 'kategori_id', 'satuan_id']);
        });
    }
};
