<?php

use App\Models\DeviceModel;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        $deviceModels = [
            [
                'name' => 'og_png',
                'label' => 'TRMNL OG (1-bit)',
                'description' => 'TRMNL OG (1-bit)',
                'width' => 800,
                'height' => 480,
                'colors' => 2,
                'bit_depth' => 1,
                'scale_factor' => 1,
                'rotation' => 0,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'og_plus',
                'label' => 'TRMNL OG (2-bit)',
                'description' => 'TRMNL OG (2-bit)',
                'width' => 800,
                'height' => 480,
                'colors' => 4,
                'bit_depth' => 2,
                'scale_factor' => 1,
                'rotation' => 0,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'amazon_kindle_2024',
                'label' => 'Amazon Kindle 2024',
                'description' => 'Amazon Kindle 2024',
                'width' => 1400,
                'height' => 840,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 2.414,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 75,
                'offset_y' => 25,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'amazon_kindle_paperwhite_6th_gen',
                'label' => 'Amazon Kindle PW 6th Gen',
                'description' => 'Amazon Kindle PW 6th Gen',
                'width' => 1024,
                'height' => 768,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'amazon_kindle_paperwhite_7th_gen',
                'label' => 'Amazon Kindle PW 7th Gen',
                'description' => 'Amazon Kindle PW 7th Gen',
                'width' => 1448,
                'height' => 1072,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'inkplate_10',
                'label' => 'Inkplate 10',
                'description' => 'Inkplate 10',
                'width' => 1200,
                'height' => 820,
                'colors' => 8,
                'bit_depth' => 3,
                'scale_factor' => 1,
                'rotation' => 0,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'amazon_kindle_7',
                'label' => 'Amazon Kindle 7',
                'description' => 'Amazon Kindle 7',
                'width' => 800,
                'height' => 600,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'inky_impression_7_3',
                'label' => 'Inky Impression 7.3',
                'description' => 'Inky Impression 7.3',
                'width' => 800,
                'height' => 480,
                'colors' => 2,
                'bit_depth' => 1,
                'scale_factor' => 1,
                'rotation' => 0,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'kobo_libra_2',
                'label' => 'Kobo Libra 2',
                'description' => 'Kobo Libra 2',
                'width' => 1680,
                'height' => 1264,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'amazon_kindle_oasis_2',
                'label' => 'Amazon Kindle Oasis 2',
                'description' => 'Amazon Kindle Oasis 2',
                'width' => 1680,
                'height' => 1264,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'kobo_aura_one',
                'label' => 'Kobo Aura One',
                'description' => 'Kobo Aura One',
                'width' => 1872,
                'height' => 1404,
                'colors' => 256,
                'bit_depth' => 8,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'kobo_aura_hd',
                'label' => 'Kobo Aura HD',
                'description' => 'Kobo Aura HD',
                'width' => 1440,
                'height' => 1080,
                'colors' => 16,
                'bit_depth' => 4,
                'scale_factor' => 1,
                'rotation' => 90,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
            [
                'name' => 'inky_impression_13_3',
                'label' => 'Inky Impression 13.3',
                'description' => 'Inky Impression 13.3',
                'width' => 1600,
                'height' => 1200,
                'colors' => 2,
                'bit_depth' => 1,
                'scale_factor' => 1,
                'rotation' => 0,
                'mime_type' => 'image/png',
                'offset_x' => 0,
                'offset_y' => 0,
                'published_at' => '2024-01-01 00:00:00',
                'source' => 'api',
                'created_at' => now(),
                'updated_at' => now(),
            ],
        ];

        // Upsert by unique 'name' to avoid duplicates and keep data fresh
        DeviceModel::query()->upsert(
            $deviceModels,
            ['name'],
            [
                'label', 'description', 'width', 'height', 'colors', 'bit_depth', 'scale_factor',
                'rotation', 'mime_type', 'offset_x', 'offset_y', 'published_at', 'source',
                'created_at', 'updated_at',
            ]
        );
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $names = [
            'og_png',
            'amazon_kindle_2024',
            'amazon_kindle_paperwhite_6th_gen',
            'amazon_kindle_paperwhite_7th_gen',
            'inkplate_10',
            'amazon_kindle_7',
            'inky_impression_7_3',
            'kobo_libra_2',
            'amazon_kindle_oasis_2',
            'og_plus',
            'kobo_aura_one',
            'kobo_aura_hd',
            'inky_impression_13_3',
        ];

        DeviceModel::query()->whereIn('name', $names)->delete();
    }
};
