<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Phase 1A of the real-device-frames feature. Adds three columns on
 * `device_presets` so an existing preset row can opt in to a photorealistic
 * PNG frame alongside the procedural bezel:
 *
 *   has_real_frame           — boolean opt-in flag, defaults false
 *   real_frame_color_options — JSON list of { slug, label, swatch } entries
 *                              mirrored from public/device-frames/manifest.json
 *   real_frame_screen_rect   — JSON map of { portrait, landscape } → { x, y,
 *                              width, height, radius } screen cutout coords
 *                              the renderer uses to position the user's
 *                              screenshot under the frame PNG.
 *
 * Defaults keep existing presets on the procedural-only path (`has_real_frame
 * = false`, null JSON columns) — zero behavior change until a sibling
 * backfill migration flips matching keys based on the manifest.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('device_presets', function (Blueprint $table) {
            $table->boolean('has_real_frame')->default(false)->after('family_id');
            $table->json('real_frame_color_options')->nullable()->after('has_real_frame');
            $table->json('real_frame_screen_rect')->nullable()->after('real_frame_color_options');
        });
    }

    public function down(): void
    {
        Schema::table('device_presets', function (Blueprint $table) {
            $table->dropColumn([
                'has_real_frame',
                'real_frame_color_options',
                'real_frame_screen_rect',
            ]);
        });
    }
};
