<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        // Kunci Pengaman: Cek dulu, kalau di MySQL sudah ada tabel keluhans, jangan dibuat lagi!
        if (!Schema::hasTable('keluhans')) {
            Schema::create('keluhans', function (Blueprint $table) {
                $table->id();
                $table->foreignId('transaksi_id')->constrained('transaksis')->onDelete('cascade');
                $table->foreignId('pelanggan_id')->constrained('pelanggan')->onDelete('cascade');
                $table->string('judul_keluhan');
                $table->text('isi_keluhan');
                $table->enum('status', ['terbuka', 'diproses', 'selesai'])->default('terbuka');
                $table->text('solusi_admin')->nullable();
                $table->timestamps();
            });
        }
    }

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