<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

/**
 * "Installs" GuidedTour by setting the {name}_version system property.
 * ModuleUtil::getModuleData() only collects get_additional_script from modules
 * reported installed by ModuleUtil::isModuleInstalled() (which reads
 * strtolower(name).'_version'). Without this row the "Play tour" launcher never
 * injects — so this migration makes `php artisan migrate` install it. Idempotent.
 */
return new class extends Migration
{
    public function up(): void
    {
        if (! DB::table('system')->where('key', 'guidedtour_version')->exists()) {
            DB::table('system')->insert(['key' => 'guidedtour_version', 'value' => '1.0.0']);
        }
    }

    public function down(): void
    {
        DB::table('system')->where('key', 'guidedtour_version')->delete();
    }
};
