<?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::create('feature_toggles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->string('description')->nullable();
            $table->string('type')->default('button'); // button, section, module, menu
            $table->string('location')->nullable(); // header, footer, hero, sidebar, etc.
            $table->boolean('is_active')->default(true);
            $table->boolean('requires_auth')->default(false);
            $table->string('visibility_condition')->nullable(); // always, date_range, user_status, submission_status
            $table->timestamp('visible_from')->nullable();
            $table->timestamp('visible_until')->nullable();
            $table->json('condition_rules')->nullable(); // For complex conditions like {"submission_status": "approved"}
            $table->string('button_text')->nullable();
            $table->string('button_url')->nullable();
            $table->string('button_style')->nullable(); // primary, secondary, outline
            $table->integer('order')->default(0);
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('feature_toggles');
    }
};
