<?php

declare(strict_types=1);

namespace Database\Seeders;

use App\Models\Plan;
use Illuminate\Database\Seeder;

class PlanSeeder extends Seeder
{
    public function run(): void
    {
        // Archive old VPS plans instead of deleting (preserves foreign key relationships)
        Plan::query()
            ->where('service_type', 'vps')
            ->whereNotIn('slug', [
                'vps-nano', 'vps-micro', 'vps-mini', 'vps-standard',
                'vps-plus', 'vps-pro', 'vps-storage-500', 'vps-storage-1tb',
            ])
            ->update(['status' => 'archived']);

        $plans = [
            // ─── VPS Plans (2026 NVMe Lineup) ────────────────────────────
            [
                'name' => 'Nano',
                'slug' => 'vps-nano',
                'description' => 'Entry-level NVMe VPS for simple tasks, testing, and lightweight applications.',
                'service_type' => 'vps',
                'price' => 3.50,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '1 vCPU',
                    'ram' => '1 GB',
                    'storage' => '15 GB NVMe',
                    'bandwidth' => '2 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 1,
            ],
            [
                'name' => 'Micro',
                'slug' => 'vps-micro',
                'description' => 'NVMe VPS with 2 GB RAM - double the RAM of competitors at the same price point.',
                'service_type' => 'vps',
                'price' => 5.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '1 vCPU',
                    'ram' => '2 GB',
                    'storage' => '30 GB NVMe',
                    'bandwidth' => '3 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 2,
            ],
            [
                'name' => 'Mini',
                'slug' => 'vps-mini',
                'description' => 'Hero plan with 4 GB RAM and NVMe storage - beats Hetzner CX22 with faster disks.',
                'service_type' => 'vps',
                'price' => 8.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2 vCPU',
                    'ram' => '4 GB',
                    'storage' => '50 GB NVMe',
                    'bandwidth' => '4 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 3,
            ],
            [
                'name' => 'Standard',
                'slug' => 'vps-standard',
                'description' => 'Premium 8 GB RAM VPS with NVMe - double the RAM of competitors at half the price.',
                'service_type' => 'vps',
                'price' => 14.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2 vCPU',
                    'ram' => '8 GB',
                    'storage' => '80 GB NVMe',
                    'bandwidth' => '6 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 4,
            ],
            [
                'name' => 'Plus',
                'slug' => 'vps-plus',
                'description' => 'High-RAM VPS with 12 GB memory and quad-core CPU for demanding applications.',
                'service_type' => 'vps',
                'price' => 22.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '4 vCPU',
                    'ram' => '12 GB',
                    'storage' => '120 GB NVMe',
                    'bandwidth' => '8 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 5,
            ],
            [
                'name' => 'Pro',
                'slug' => 'vps-pro',
                'description' => 'Ultimate RAM VPS with 16 GB memory and NVMe for production workloads.',
                'service_type' => 'vps',
                'price' => 29.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '4 vCPU',
                    'ram' => '16 GB',
                    'storage' => '160 GB NVMe',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 6,
            ],
            [
                'name' => 'Storage-500',
                'slug' => 'vps-storage-500',
                'description' => 'Storage-focused VPS with 500 GB SATA SSD for backups, media, and file storage.',
                'service_type' => 'vps',
                'price' => 24.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2 vCPU',
                    'ram' => '4 GB',
                    'storage' => '500 GB SSD',
                    'bandwidth' => '8 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 7,
            ],
            [
                'name' => 'Storage-1TB',
                'slug' => 'vps-storage-1tb',
                'description' => 'Mass storage VPS with 1 TB SATA SSD for large-scale file storage and archives.',
                'service_type' => 'vps',
                'price' => 44.95,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '4 vCPU',
                    'ram' => '8 GB',
                    'storage' => '1 TB SSD',
                    'bandwidth' => '12 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                    'virtfusion_package_id' => 1,
                    'virtfusion_user_id' => 1,
                    'virtfusion_hypervisor_id' => 1,
                ],
                'sort_order' => 8,
            ],

            // ─── Dedicated Server Plans ──────────────────────────────────
            [
                'name' => 'Dell R330 LFF',
                'slug' => 'dell-r330-lff',
                'description' => 'Entry-level single-socket dedicated server with 4 large form factor drive bays.',
                'service_type' => 'dedicated',
                'price' => 44.39,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '1x Intel Xeon E3-1220 v5',
                    'cores' => '4C/4T',
                    'ram' => '16 GB',
                    'storage_bays' => '4x 3.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 3,
                'sort_order' => 10,
            ],
            [
                'name' => 'Dell R420 LFF',
                'slug' => 'dell-r420-lff',
                'description' => 'Dual-socket server with 12 cores and 32 GB RAM for mid-range workloads.',
                'service_type' => 'dedicated',
                'price' => 58.79,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2430v2',
                    'cores' => '12C/24T',
                    'ram' => '32 GB',
                    'storage_bays' => '4x 3.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 0,
                'sort_order' => 11,
            ],
            [
                'name' => 'Dell R620 SFF 10-Bay',
                'slug' => 'dell-r620-sff-10-bay',
                'description' => 'High-performance 1U server with 10 small form factor bays and 16 cores.',
                'service_type' => 'dedicated',
                'price' => 61.19,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2667v2',
                    'cores' => '16C/32T',
                    'ram' => '32 GB',
                    'storage_bays' => '10x 2.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 0,
                'sort_order' => 12,
            ],
            [
                'name' => 'Dell R620 SFF 8-Bay',
                'slug' => 'dell-r620-sff-8-bay',
                'description' => 'High-performance 1U server with 8 small form factor bays and 16 cores.',
                'service_type' => 'dedicated',
                'price' => 61.19,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2667v2',
                    'cores' => '16C/32T',
                    'ram' => '32 GB',
                    'storage_bays' => '8x 2.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 0,
                'sort_order' => 13,
            ],
            [
                'name' => 'Dell R520 LFF',
                'slug' => 'dell-r520-lff',
                'description' => 'Storage-friendly 2U server with 8 large form factor bays and dual Xeons.',
                'service_type' => 'dedicated',
                'price' => 64.79,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2420v2',
                    'cores' => '12C/24T',
                    'ram' => '32 GB',
                    'storage_bays' => '8x 3.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 2,
                'sort_order' => 14,
            ],
            [
                'name' => 'Dell R430 LFF',
                'slug' => 'dell-r430-lff',
                'description' => 'Compact 1U server with high-clock v4 Xeons for compute-intensive tasks.',
                'service_type' => 'dedicated',
                'price' => 87.59,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2667v4',
                    'cores' => '16C/32T',
                    'ram' => '32 GB',
                    'storage_bays' => '4x 3.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 1,
                'sort_order' => 15,
            ],
            [
                'name' => 'Dell R630 SFF',
                'slug' => 'dell-r630-sff',
                'description' => 'High-core-count 1U server with 32 cores and 64 threads for heavy multi-threaded workloads.',
                'service_type' => 'dedicated',
                'price' => 93.59,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2697A v4',
                    'cores' => '32C/64T',
                    'ram' => '32 GB',
                    'storage_bays' => '8x 2.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 1,
                'sort_order' => 16,
            ],
            [
                'name' => 'Dell R730 LFF',
                'slug' => 'dell-r730-lff',
                'description' => 'Flagship 2U server with 28 cores, 56 threads, and 8 large form factor bays.',
                'service_type' => 'dedicated',
                'price' => 107.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'cpu' => '2x Intel Xeon E5-2680v4',
                    'cores' => '28C/56T',
                    'ram' => '32 GB',
                    'storage_bays' => '8x 3.5" bays',
                    'bandwidth' => '10 TB',
                    'ipv4' => '1 IPv4',
                    'ipv6' => '1 /64 IPv6',
                    'management' => 'SynergyCP',
                ],
                'stock_quantity' => 1,
                'sort_order' => 17,
            ],

            // ─── Web Hosting Plans ───────────────────────────────────────
            [
                'name' => 'Small',
                'slug' => 'hosting-small',
                'description' => 'Starter web hosting plan for personal sites and blogs.',
                'service_type' => 'hosting',
                'price' => 2.39,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '10 GB SSD',
                    'databases' => '2 MySQL',
                    'email' => '5 Accounts',
                    'domains' => '1',
                    'bandwidth' => '1 TB',
                    'ram' => '512 MB',
                    'cpu' => '1 Core',
                    'ssl' => 'Free SSL',
                    'panel' => 'Enhance',
                ],
                'sort_order' => 20,
            ],
            [
                'name' => 'Medium',
                'slug' => 'hosting-medium',
                'description' => 'Mid-range hosting for small businesses and growing websites.',
                'service_type' => 'hosting',
                'price' => 3.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '25 GB SSD',
                    'databases' => '6 MySQL',
                    'email' => '20 Accounts',
                    'domains' => '4',
                    'bandwidth' => '1 TB',
                    'ram' => '1 GB',
                    'cpu' => '1 Core',
                    'ssl' => 'Free SSL',
                    'panel' => 'Enhance',
                ],
                'sort_order' => 21,
            ],
            [
                'name' => 'Large',
                'slug' => 'hosting-large',
                'description' => 'High-capacity hosting with unlimited databases and email for agencies and power users.',
                'service_type' => 'hosting',
                'price' => 7.19,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '100 GB SSD',
                    'databases' => 'Unlimited MySQL',
                    'email' => 'Unlimited Accounts',
                    'domains' => '30',
                    'bandwidth' => '2 TB',
                    'ram' => '4 GB',
                    'cpu' => '4 Cores',
                    'ssl' => 'Free SSL',
                    'panel' => 'Enhance',
                ],
                'sort_order' => 22,
            ],
            [
                'name' => 'Dedicated',
                'slug' => 'hosting-dedicated',
                'description' => 'Dedicated hosting resources with maximum performance and capacity.',
                'service_type' => 'hosting',
                'price' => 15.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '160 GB SSD',
                    'databases' => 'Unlimited MySQL',
                    'email' => 'Unlimited Accounts',
                    'domains' => '100',
                    'bandwidth' => '4 TB',
                    'ram' => '8 GB',
                    'cpu' => '4 Cores',
                    'ssl' => 'Free SSL',
                    'panel' => 'Enhance',
                ],
                'sort_order' => 23,
            ],

            // ─── Game Server Plans ──────────────────────────────────────
            [
                'name' => 'Minecraft',
                'slug' => 'game-minecraft',
                'description' => 'Java & Bedrock Minecraft server with full mod support.',
                'service_type' => 'game',
                'price' => 7.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => '2 GB',
                    'slots' => '20 Players',
                    'storage' => '10 GB SSD',
                    'cpu' => '2 Threads',
                    'mods' => 'Full Mod Support',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 40,
            ],
            [
                'name' => 'Rust',
                'slug' => 'game-rust',
                'description' => 'High-performance Rust server with Oxide/uMod support.',
                'service_type' => 'game',
                'price' => 14.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => '4 GB',
                    'slots' => '50 Players',
                    'storage' => '25 GB SSD',
                    'cpu' => '3 Threads',
                    'mods' => 'Oxide/uMod Support',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 41,
            ],
            [
                'name' => 'ARK: Survival Evolved',
                'slug' => 'game-ark',
                'description' => 'ARK servers with cluster support and full mod compatibility.',
                'service_type' => 'game',
                'price' => 19.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => '8 GB',
                    'slots' => '30 Players',
                    'storage' => '50 GB SSD',
                    'cpu' => '4 Threads',
                    'mods' => 'Full Mod Support',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 42,
            ],
            [
                'name' => 'Valheim',
                'slug' => 'game-valheim',
                'description' => 'Dedicated Valheim server with BepInEx mod support.',
                'service_type' => 'game',
                'price' => 9.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => '4 GB',
                    'slots' => '10 Players',
                    'storage' => '10 GB SSD',
                    'cpu' => '2 Threads',
                    'mods' => 'BepInEx Support',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 43,
            ],
            [
                'name' => 'CS2',
                'slug' => 'game-cs2',
                'description' => 'Counter-Strike 2 competitive and casual servers.',
                'service_type' => 'game',
                'price' => 12.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => '4 GB',
                    'slots' => '32 Players',
                    'storage' => '15 GB SSD',
                    'cpu' => '3 Threads',
                    'mods' => 'Workshop Support',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 44,
            ],
            [
                'name' => 'Palworld',
                'slug' => 'game-palworld',
                'description' => 'Palworld dedicated server with full configuration.',
                'service_type' => 'game',
                'price' => 14.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => '8 GB',
                    'slots' => '32 Players',
                    'storage' => '20 GB SSD',
                    'cpu' => '4 Threads',
                    'mods' => 'Community Mods',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 45,
            ],

            // ─── MySQL Hosting Plans ─────────────────────────────────────
            [
                'name' => 'Bronze',
                'slug' => 'mysql-bronze',
                'description' => 'Entry-level managed MySQL hosting with daily backups.',
                'service_type' => 'mysql',
                'price' => 6.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '5 GB',
                    'backups' => 'Daily',
                    'ssl' => 'SSL Encrypted',
                ],
                'sort_order' => 30,
            ],
            [
                'name' => 'Silver',
                'slug' => 'mysql-silver',
                'description' => 'Mid-tier managed MySQL hosting for growing applications.',
                'service_type' => 'mysql',
                'price' => 12.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '15 GB',
                    'backups' => 'Daily',
                    'ssl' => 'SSL Encrypted',
                ],
                'sort_order' => 31,
            ],
            [
                'name' => 'Gold',
                'slug' => 'mysql-gold',
                'description' => 'High-capacity managed MySQL hosting for production databases.',
                'service_type' => 'mysql',
                'price' => 18.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '30 GB',
                    'backups' => 'Daily',
                    'ssl' => 'SSL Encrypted',
                ],
                'sort_order' => 32,
            ],
            [
                'name' => 'Platinum',
                'slug' => 'mysql-platinum',
                'description' => 'Enterprise managed MySQL hosting with 100 GB storage for large-scale databases.',
                'service_type' => 'mysql',
                'price' => 30.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '100 GB',
                    'backups' => 'Daily',
                    'ssl' => 'SSL Encrypted',
                ],
                'sort_order' => 33,
            ],
        ];

        foreach ($plans as $plan) {
            Plan::updateOrCreate(
                ['slug' => $plan['slug']],
                array_merge([
                    'currency' => 'USD',
                    'status' => 'active',
                ], $plan),
            );
        }
    }
}
