<?php

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

/**
 * Seed Samsung Galaxy S26 device preset (portrait + landscape) with the
 * full 5-color real-frame bundle. Dimensions mirror Galaxy S24's
 * specs (1080×2340 portrait) as a baseline until Samsung publishes the
 * S26's official screenshot tiers.
 *
 * Real-frame screen-rect geometry measured from the source PNGs at
 * 1790×3690 native (cutout 1634×3540, 9:19.5 aspect — modern phone).
 */
return new class extends Migration
{
    public function up(): void
    {
        $now = now();

        $colors = [
            ['slug' => 'black',      'label' => 'Black',      'swatch' => '#0E0E10'],
            ['slug' => 'real-light', 'label' => 'Real Light', 'swatch' => '#E7E2D9'],
            ['slug' => 'real-gold',  'label' => 'Real Gold',  'swatch' => '#C8B68C'],
            ['slug' => 'light',      'label' => 'Light',      'swatch' => '#DCDCDC'],
            ['slug' => 'dark',       'label' => 'Dark',       'swatch' => '#393B3F'],
        ];

        $screenRect = [
            'portrait' => [
                'x' => 75,
                'y' => 75,
                'width' => 1634,
                'height' => 3540,
                'radius' => 64,
                'frame_w' => 1790,
                'frame_h' => 3690,
            ],
            'landscape' => [
                'x' => 75,
                'y' => 75,
                'width' => 3540,
                'height' => 1634,
                'radius' => 64,
                'frame_w' => 3690,
                'frame_h' => 1790,
            ],
        ];

        // Safe-area: status bar 80px top, nav 48px bottom — same proportions
        // every other Galaxy device preset uses.
        $safeArea = json_encode(['top' => 80, 'right' => 0, 'bottom' => 48, 'left' => 0]);

        DB::transaction(function () use ($colors, $screenRect, $safeArea, $now) {
            DB::table('device_presets')->updateOrInsert(
                ['key' => 'android-galaxy-s26'],
                [
                    'label' => 'Galaxy S26',
                    'platform' => 'android',
                    'category' => 'phone',
                    'form_factor' => 'android_phone_portrait',
                    'apple_tier' => null,
                    'export_w' => 1080,
                    'export_h' => 2340,
                    'frame_svg_path' => null,
                    'safe_area' => $safeArea,
                    'has_real_frame' => true,
                    'real_frame_color_options' => json_encode($colors),
                    'real_frame_screen_rect' => json_encode($screenRect),
                    'is_active' => true,
                    'created_at' => $now,
                    'updated_at' => $now,
                ],
            );

            DB::table('device_presets')->updateOrInsert(
                ['key' => 'android-galaxy-s26-landscape'],
                [
                    'label' => 'Galaxy S26 (Landscape)',
                    'platform' => 'android',
                    'category' => 'phone',
                    'form_factor' => 'android_phone_landscape',
                    'apple_tier' => null,
                    'export_w' => 2340,
                    'export_h' => 1080,
                    'frame_svg_path' => null,
                    // Landscape safe-area: nav bar moves to the right edge on
                    // most devices, status bar stays top.
                    'safe_area' => json_encode(['top' => 80, 'right' => 48, 'bottom' => 0, 'left' => 0]),
                    'has_real_frame' => true,
                    'real_frame_color_options' => json_encode($colors),
                    'real_frame_screen_rect' => json_encode($screenRect),
                    'is_active' => true,
                    'created_at' => $now,
                    'updated_at' => $now,
                ],
            );
        });
    }

    public function down(): void
    {
        DB::table('device_presets')
            ->whereIn('key', ['android-galaxy-s26', 'android-galaxy-s26-landscape'])
            ->delete();
    }
};
