<?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('qr_codes', function (Blueprint $table) {
            $table->id();
            $table->string('short_code', 12)->unique();
            $table->string('name');
            $table->string('type', 20);
            $table->json('payload')->nullable();
            $table->text('target_url')->nullable();
            $table->boolean('is_dynamic')->default(true);
            $table->boolean('is_active')->default(true);
            $table->unsignedBigInteger('scan_count')->default(0);
            $table->timestamp('last_scanned_at')->nullable();
            $table->timestamps();

            // Soft deletes instead of a hard delete: printed QR codes point at
            // `/q/{short_code}` indefinitely, so removing the row outright
            // would silently break a physical code still in circulation.
            $table->softDeletes();
        });
    }

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