<?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
    {
        if (! Schema::hasTable('tour_steps')) {
            Schema::create('tour_steps', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('flow_id');
                $table->unsignedInteger('sort_order')->default(0);
                $table->string('route', 255)->nullable();          // relative path the step lives on (e.g. /vet-clinic/appointments)
                $table->string('target_selector', 255)->nullable();// CSS selector to spotlight; null = centered modal
                $table->string('title', 200);
                $table->text('body_html')->nullable();
                $table->unsignedInteger('media_id')->nullable();
                $table->string('placement', 20)->default('auto');  // auto|top|bottom|left|right|center
                $table->timestamps();

                $table->index(['flow_id', 'sort_order']);
                $table->foreign('flow_id')->references('id')->on('tour_flows')->onDelete('cascade');
                $table->foreign('media_id')->references('id')->on('tour_media')->onDelete('set null');
            });
        }
    }

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