<?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
    {
        Schema::create('SubKategori', function (Blueprint $table) {
            $table->id('SubKategoriId');
            $table->unsignedBigInteger('KategoriId');
            $table->string('NamaSubKategori');
            $table->softDeletes();
            $table->timestamps();

            // Foreign key ke tabel Kategori
            $table->foreign('KategoriId')->references('KategoriId')->on('Kategori')->onDelete('cascade');

            // UNIQUE constraint untuk memastikan kategori & subkategori tidak duplikat
            $table->unique(['KategoriId', 'NamaSubKategori']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('SubKategori');
    }
};
