<?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('product_types', function (Blueprint $table) {
            $table->id();
            $table->string('code', 50)->unique();
            $table->string('name');
            $table->string('slug')->unique();
            $table->string('icon')->nullable();
            $table->text('description')->nullable();

            // Feature Flags
            $table->boolean('has_categories')->default(true);
            $table->boolean('has_pricing')->default(true);
            $table->boolean('has_booking')->default(true);
            $table->boolean('has_itinerary')->default(false);
            $table->boolean('has_dates')->default(true);

            // Configuration
            $table->json('config_schema')->nullable();
            $table->json('form_fields')->nullable();
            $table->string('model_class')->nullable();
            $table->string('controller_class')->nullable();

            // Display
            $table->integer('sort_order')->default(0);
            $table->boolean('is_active')->default(true);
            $table->boolean('is_system')->default(false);

            $table->timestamps();

            // Indexes
            $table->index(['is_active', 'sort_order']);
        });
    }

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