<?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('preferences', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade'); // Reference to the user who set the preferences
            $table->string('filters')->nullable();

            // Checkbox fields for filters
            $table->json('bidang_sub_sektor_ekonomi_kreatif')->nullable(); // JSON for multiple 'bidang'
            $table->json('kategori')->nullable(); // JSON for multiple 'kategori'
            $table->date('batas_terima_tawaran')->nullable(); // Date for 'Batas Terima Tawaran'

            // Range Biaya dan Jumlah Dana (only for pemerintah and investor roles)
            $table->decimal('range_min', 20, 2)->nullable();
            $table->decimal('range_max', 20, 2)->nullable();

            // Status, Audiens, Benefit, Durasi, Lokasi, Metodologi, Rincian Kebutuhan, Penerima Manfaat
            $table->json('status')->nullable(); // JSON for multiple 'status'
            $table->text('audiens')->nullable();
            $table->text('benefit')->nullable();
            $table->integer('durasi_min')->nullable();
            $table->integer('durasi_max')->nullable();
            $table->string('lokasi')->nullable();
            $table->text('metodologi')->nullable();
            $table->text('rincian_kebutuhan')->nullable();
            $table->text('penerima_manfaat')->nullable();
            $table->timestamps();
        });
    }

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