<?php

declare(strict_types=1);

namespace Database\Seeders;

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

class PlanSeeder extends Seeder
{
    public function run(): void
    {
        // Archive old VPS plans (preserves foreign key relationships)
        Plan::query()
            ->where('service_type', 'vps')
            ->whereNotIn('slug', [
                'vps-1', 'vps-2', 'vps-3-custom', 'vps-4', 'vps-8', 'vps-16', 'vps-32',
                'stor-500', 'stor-1tb',
            ])
            ->update(['status' => 'inactive']);

        // ─── Existing 12th/13th-gen dedicated plans stay rentable as
        // ─── "in stock" inventory alongside the new 14th-gen build-to-
        // ─── order line. Their status is set per-row in the seeder
        // ─── definitions below.

        $plans = [
            // ─── VPS Plans ─────────────────────────────────────────────────
            [
                'name' => 'VPS-1',
                'slug' => 'vps-1',
                'description' => 'Entry-level VPS with 1 GB RAM for simple tasks, testing, and lightweight applications.',
                'service_type' => 'vps',
                'price' => 5.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 1,
                    'cpu' => '1 vCPU',
                    'ram' => '1 GB',
                    'storage' => '25 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 44, 'hypervisor_id' => 1],
                'sort_order' => 1,
            ],
            [
                'name' => 'VPS-2',
                'slug' => 'vps-2',
                'description' => 'VPS with 2 GB RAM for small web apps, development servers, and lightweight services.',
                'service_type' => 'vps',
                'price' => 8.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 2,
                    'cpu' => '1 vCPU',
                    'ram' => '2 GB',
                    'storage' => '50 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 45, 'hypervisor_id' => 1],
                'sort_order' => 2,
            ],
            [
                'name' => 'VPS-3 Custom',
                'slug' => 'vps-3-custom',
                'description' => 'Custom VPS plan for grandfathered customers. Not available for new signups.',
                'service_type' => 'vps',
                'price' => 0.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 3,
                    'cpu' => '2 vCPU',
                    'ram' => '3 GB',
                    'storage' => '60 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 47, 'hypervisor_id' => 1],
                'status' => 'hidden',
                'sort_order' => 3,
            ],
            [
                'name' => 'VPS-4',
                'slug' => 'vps-4',
                'description' => 'VPS with 4 GB RAM and dual vCPUs for web hosting, databases, and moderate workloads.',
                'service_type' => 'vps',
                'price' => 15.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 4,
                    'cpu' => '2 vCPU',
                    'ram' => '4 GB',
                    'storage' => '80 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 46, 'hypervisor_id' => 1],
                'sort_order' => 4,
            ],
            [
                'name' => 'VPS-8',
                'slug' => 'vps-8',
                'description' => 'VPS with 8 GB RAM and quad vCPUs for production workloads and demanding applications.',
                'service_type' => 'vps',
                'price' => 30.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 8,
                    'cpu' => '4 vCPU',
                    'ram' => '8 GB',
                    'storage' => '160 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 47, 'hypervisor_id' => 1],
                'sort_order' => 5,
            ],
            [
                'name' => 'VPS-16',
                'slug' => 'vps-16',
                'description' => 'High-performance VPS with 16 GB RAM and 6 vCPUs for heavy multi-threaded workloads.',
                'service_type' => 'vps',
                'price' => 55.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 16,
                    'cpu' => '6 vCPU',
                    'ram' => '16 GB',
                    'storage' => '320 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 48, 'hypervisor_id' => 1],
                'sort_order' => 6,
            ],
            [
                'name' => 'VPS-32',
                'slug' => 'vps-32',
                'description' => 'Ultimate VPS with 32 GB RAM and 8 vCPUs for enterprise-grade production environments.',
                'service_type' => 'vps',
                'price' => 99.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 32,
                    'cpu' => '8 vCPU',
                    'ram' => '32 GB',
                    'storage' => '640 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 49, 'hypervisor_id' => 1],
                'sort_order' => 7,
            ],
            [
                'name' => 'Storage 500',
                'slug' => 'stor-500',
                'description' => 'Storage-focused VPS with 500 GB SSD for backups, media, and file storage.',
                'service_type' => 'vps',
                'price' => 18.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 4,
                    'cpu' => '2 vCPU',
                    'ram' => '2 GB',
                    'storage' => '500 GB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 50, 'hypervisor_id' => 1],
                'sort_order' => 8,
            ],
            [
                'name' => 'Storage 1TB',
                'slug' => 'stor-1tb',
                'description' => 'Mass storage VPS with 1 TB SSD for large-scale file storage and archives.',
                'service_type' => 'vps',
                'price' => 28.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'tier' => 4,
                    'cpu' => '2 vCPU',
                    'ram' => '4 GB',
                    'storage' => '1 TB SSD',
                    'bandwidth' => 'Unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'control_panel' => 'VirtFusion',
                    'os' => 'Linux & Windows (BYOL)',
                ],
                'provisioning_config' => ['package_id' => 51, 'hypervisor_id' => 1],
                'sort_order' => 9,
            ],

            // ─── Dedicated Server Plans — In-Stock 12th/13th Gen (rack inventory) ───
            [
                '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',
                    'generation' => '12th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 3,
                'sort_order' => 100,
            ],
            [
                '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',
                    'generation' => '12th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 0,
                'sort_order' => 101,
            ],
            [
                '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',
                    'generation' => '12th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 0,
                'sort_order' => 102,
            ],
            [
                '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',
                    'generation' => '12th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 0,
                'sort_order' => 103,
            ],
            [
                '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',
                    'generation' => '12th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 2,
                'sort_order' => 104,
            ],
            [
                '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',
                    'generation' => '13th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 1,
                'sort_order' => 105,
            ],
            [
                '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',
                    'generation' => '13th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 1,
                'sort_order' => 106,
            ],
            [
                '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',
                    'generation' => '13th-gen',
                ],
                'status' => 'active',
                'stock_quantity' => 1,
                'sort_order' => 107,
            ],

            // ─── Dedicated Server Plans — Build-to-Order 14th Gen ───────────
            [
                'name' => 'Dell R440 — 4-Bay LFF (1U)',
                'slug' => 'r440-4lff',
                'description' => 'Entry-level dual-socket 14th-gen rackmount. Ideal for small databases, web hosting, or budget compute. Built to order in 7-10 business days from our Atlanta datacenter.',
                'service_type' => 'dedicated',
                'price' => 119.00,
                'setup_fee' => 349.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R440',
                    'form_factor' => '1U',
                    'bays' => '4x 3.5" LFF',
                    'bay_count' => 4,
                    'bay_type' => 'LFF',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (Non-RAID, IT mode)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 2,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 10,
            ],
            [
                'name' => 'Dell R540 — 8-Bay LFF (2U)',
                'slug' => 'r540-8lff',
                'description' => 'Storage-optimized 2U server. Perfect for ZFS file servers, backup targets, and bulk media storage. Built to order in 7-10 business days.',
                'service_type' => 'dedicated',
                'price' => 159.00,
                'setup_fee' => 549.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R540',
                    'form_factor' => '2U',
                    'bays' => '8x 3.5" LFF',
                    'bay_count' => 8,
                    'bay_type' => 'LFF',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (Non-RAID, IT mode)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 3,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 11,
            ],
            [
                'name' => 'Dell R640 — 8-Bay SFF (1U)',
                'slug' => 'r640-8sff',
                'description' => 'High-performance 1U with 8 SFF bays. Best fit for application servers, mid-tier databases, and virtualization.',
                'service_type' => 'dedicated',
                'price' => 179.00,
                'setup_fee' => 349.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R640',
                    'form_factor' => '1U',
                    'bays' => '8x 2.5" SFF',
                    'bay_count' => 8,
                    'bay_type' => 'SFF',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (Non-RAID, mini)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 2,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 12,
            ],
            [
                'name' => 'Dell R740 — 16-Bay SFF (2U)',
                'slug' => 'r740-16sff',
                'description' => 'Dense 2U server with 16 SFF bays. Built for high-performance workloads, large SSD arrays, and VPS host nodes.',
                'service_type' => 'dedicated',
                'price' => 229.00,
                'setup_fee' => 549.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R740',
                    'form_factor' => '2U',
                    'bays' => '16x 2.5" SFF',
                    'bay_count' => 16,
                    'bay_type' => 'SFF',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (Non-RAID, mini)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 3,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 13,
            ],
            [
                'name' => 'Dell R740xd — 24-Bay SFF (2U)',
                'slug' => 'r740xd-24sff',
                'description' => 'Maximum SFF density: 24 small form-factor bays for large SSD arrays, distributed storage, and supercluster nodes.',
                'service_type' => 'dedicated',
                'price' => 279.00,
                'setup_fee' => 549.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R740xd',
                    'form_factor' => '2U',
                    'bays' => '24x 2.5" SFF',
                    'bay_count' => 24,
                    'bay_type' => 'SFF',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (Non-RAID, mini)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 3,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 14,
            ],
            [
                'name' => 'Dell R740xd — 12-Bay LFF (2U)',
                'slug' => 'r740xd-12lff',
                'description' => 'Bulk storage workhorse: 12 large form-factor bays for ZFS pools, archive servers, and high-capacity object stores.',
                'service_type' => 'dedicated',
                'price' => 249.00,
                'setup_fee' => 549.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R740xd',
                    'form_factor' => '2U',
                    'bays' => '12x 3.5" LFF',
                    'bay_count' => 12,
                    'bay_type' => 'LFF',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (Non-RAID, mini)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 3,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 15,
            ],
            [
                'name' => 'Dell R640 NVMe — 10-Bay U.2 (1U)',
                'slug' => 'r640-10nvme',
                'description' => 'Extreme IOPS in 1U. 10x U.2 NVMe bays for latency-sensitive databases, in-memory caches, and edge inference.',
                'service_type' => 'dedicated',
                'price' => 239.00,
                'setup_fee' => 799.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R640 NVMe',
                    'form_factor' => '1U',
                    'bays' => '10x U.2 NVMe',
                    'bay_count' => 10,
                    'bay_type' => 'NVMe',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'PERC HBA330 (drop on confirmed NVMe-only orders)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 4,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                'sort_order' => 16,
            ],
            [
                'name' => 'Dell R740xd NVMe — 24-Bay U.2 (2U)',
                'slug' => 'r740xd-24nvme',
                'description' => 'Massive-density NVMe: 24x U.2 bays direct-attached to CPU PCIe lanes. Built for distributed databases, ML training storage, and high-IOPS object stores.',
                'service_type' => 'dedicated',
                'price' => 279.00,
                'setup_fee' => 799.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'generation' => '14th-gen',
                    'chassis' => 'R740xd NVMe',
                    'form_factor' => '2U',
                    'bays' => '24x U.2 NVMe',
                    'bay_count' => 24,
                    'bay_type' => 'NVMe',
                    'cpu' => '2x Intel Xeon Gold 6230 (40C / 2.10 GHz)',
                    'cpu_class' => 'Cascade Lake Refresh',
                    'ram' => '32 GB DDR4-2400 ECC RDIMM',
                    'boot' => 'Dell BOSS — 2x 240 GB M.2 (mirrored)',
                    'storage_controller' => 'N/A — pure-PCIe, software RAID only (mdraid / ZFS / btrfs)',
                    'idrac' => 'iDRAC9 Enterprise',
                    'network' => '1x 1 GbE + 1x 10 Gbps SFP+',
                    'bandwidth' => '1 Gbps unmetered',
                    'ipv4' => '1 Included',
                    'ipv6' => '/64 Included',
                    'lead_time_days' => '7-10',
                    'tier' => 4,
                ],
                'stock_quantity' => null,
                'status' => 'active',
                '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' => 3.99,
                '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' => 6.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' => 12.99,
                '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' => 29.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,
            ],

            // ─── MySQL Hosting Plans ─────────────────────────────────────
            [
                'name' => 'Bronze',
                'slug' => 'mysql-bronze',
                'description' => 'Entry-level managed MySQL hosting with daily backups.',
                'service_type' => 'mysql',
                'price' => 7.99,
                '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' => 14.99,
                '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' => 22.99,
                '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' => 34.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'storage' => '100 GB',
                    'backups' => 'Daily',
                    'ssl' => 'SSL Encrypted',
                ],
                'sort_order' => 33,
            ],

            // ─── 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,
            ],
            [
                'name' => 'Procon Layer',
                'slug' => 'procon-layer',
                'description' => 'Battlefield server management tool. Hosted on Pterodactyl with configurable memory and disk.',
                'service_type' => 'game',
                'price' => 2.99,
                'billing_cycle' => 'monthly',
                'features' => [
                    'ram' => 'Configurable',
                    'storage' => 'Configurable',
                    'platform' => 'Pterodactyl',
                    'ddos' => 'DDoS Protection',
                ],
                'sort_order' => 50,
            ],

            // ─── Backup Plans (Veeam) ────────────────────────────────────
            [
                'name' => 'Veeam Enterprise Plus',
                'slug' => 'veeam-enterprise-plus',
                'description' => 'Enterprise-grade backup and replication. Per-VM and per-agent licensing with full Veeam feature set.',
                'service_type' => 'backups',
                'price' => 0.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'licensing' => 'Per-VM & Per-Agent',
                    'tier' => 'Enterprise Plus',
                    'replication' => 'Full Feature Set',
                ],
                'sort_order' => 60,
            ],
            [
                'name' => 'Veeam Standard',
                'slug' => 'veeam-standard',
                'description' => 'Standard backup and replication. Per-VM and per-agent licensing for essential data protection.',
                'service_type' => 'backups',
                'price' => 0.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'licensing' => 'Per-VM & Per-Agent',
                    'tier' => 'Standard',
                    'replication' => 'Essential Data Protection',
                ],
                'sort_order' => 61,
            ],
            [
                'name' => 'Veeam Cloud Connect',
                'slug' => 'veeam-cloud-connect',
                'description' => 'Cloud-connected backup with off-site replication. Capacity-based storage with optional VM replication.',
                'service_type' => 'backups',
                'price' => 0.00,
                'billing_cycle' => 'monthly',
                'features' => [
                    'licensing' => 'Capacity-Based',
                    'tier' => 'Cloud Connect',
                    'replication' => 'Off-Site VM Replication',
                ],
                'sort_order' => 62,
            ],
        ];

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

        // ─── Multi-Cycle Pricing ─────────────────────────────────────
        $allPricing = [
            // VPS Plans
            'vps-1' => ['monthly' => 5.00, 'quarterly' => 14.25, 'semi_annual' => 27.00, 'annual' => 51.00],
            'vps-2' => ['monthly' => 8.00, 'quarterly' => 22.80, 'semi_annual' => 43.20, 'annual' => 81.60],
            'vps-4' => ['monthly' => 15.00, 'quarterly' => 42.75, 'semi_annual' => 81.00, 'annual' => 153.00],
            'vps-8' => ['monthly' => 30.00, 'quarterly' => 85.50, 'semi_annual' => 162.00, 'annual' => 306.00],
            'vps-16' => ['monthly' => 55.00, 'quarterly' => 156.75, 'semi_annual' => 297.00, 'annual' => 561.00],
            'vps-32' => ['monthly' => 99.00, 'quarterly' => 282.15, 'semi_annual' => 534.60, 'annual' => 1009.80],
            'stor-500' => ['monthly' => 18.00, 'quarterly' => 51.30, 'semi_annual' => 97.20, 'annual' => 183.60],
            'stor-1tb' => ['monthly' => 28.00, 'quarterly' => 79.80, 'semi_annual' => 151.20, 'annual' => 285.60],

            // Dedicated Server Plans — Build-to-Order 14th Gen
            'r440-4lff' => ['monthly' => 119.00, 'quarterly' => 339.15, 'semi_annual' => 642.60, 'annual' => 1213.80],
            'r540-8lff' => ['monthly' => 159.00, 'quarterly' => 453.15, 'semi_annual' => 858.60, 'annual' => 1621.80],
            'r640-8sff' => ['monthly' => 179.00, 'quarterly' => 510.15, 'semi_annual' => 966.60, 'annual' => 1825.80],
            'r740-16sff' => ['monthly' => 229.00, 'quarterly' => 652.65, 'semi_annual' => 1236.60, 'annual' => 2335.80],
            'r740xd-24sff' => ['monthly' => 279.00, 'quarterly' => 795.15, 'semi_annual' => 1506.60, 'annual' => 2845.80],
            'r740xd-12lff' => ['monthly' => 249.00, 'quarterly' => 709.65, 'semi_annual' => 1344.60, 'annual' => 2539.80],
            'r640-10nvme' => ['monthly' => 239.00, 'quarterly' => 681.15, 'semi_annual' => 1290.60, 'annual' => 2437.80],
            'r740xd-24nvme' => ['monthly' => 279.00, 'quarterly' => 795.15, 'semi_annual' => 1506.60, 'annual' => 2845.80],

            // Web Hosting Plans
            'hosting-small' => ['monthly' => 3.99, 'annual' => 40.68],
            'hosting-medium' => ['monthly' => 6.99, 'annual' => 71.28],
            'hosting-large' => ['monthly' => 12.99, 'annual' => 132.48],
            'hosting-dedicated' => ['monthly' => 29.99, 'annual' => 305.88],

            // MySQL Hosting Plans
            'mysql-bronze' => ['monthly' => 7.99, 'annual' => 81.48],
            'mysql-silver' => ['monthly' => 14.99, 'annual' => 152.88],
            'mysql-gold' => ['monthly' => 22.99, 'annual' => 234.48],
            'mysql-platinum' => ['monthly' => 34.99, 'annual' => 356.88],

            // Game Server Plans
            'procon-layer' => ['monthly' => 2.99, 'annual' => 30.48],

            // Backup Plans (base price $0, all pricing via configurable options)
            'veeam-enterprise-plus' => ['monthly' => 0.00],
            'veeam-standard' => ['monthly' => 0.00],
            'veeam-cloud-connect' => ['monthly' => 0.00],
        ];

        foreach ($allPricing as $slug => $prices) {
            $plan = Plan::where('slug', $slug)->first();
            if (! $plan) {
                continue;
            }
            foreach ($prices as $cycle => $price) {
                PlanPrice::updateOrCreate(
                    ['plan_id' => $plan->id, 'billing_cycle' => $cycle],
                    ['price' => $price],
                );
            }
        }

        // ─── Build Your Own (BYO) Custom Plans ─────────────────────────
        $byoPlans = [
            ['name' => 'Custom VPS', 'slug' => 'vps-custom', 'service_type' => 'vps', 'sort_order' => 99],
            ['name' => 'Custom MySQL', 'slug' => 'mysql-custom', 'service_type' => 'mysql', 'sort_order' => 99],
            ['name' => 'Custom Game Server', 'slug' => 'game-custom', 'service_type' => 'game', 'sort_order' => 99],
        ];

        foreach ($byoPlans as $byoPlan) {
            Plan::updateOrCreate(
                ['slug' => $byoPlan['slug']],
                array_merge($byoPlan, [
                    'price' => 0.00,
                    'billing_cycle' => 'monthly',
                    'currency' => 'USD',
                    'status' => 'internal',
                    'description' => 'Custom Build Your Own plan.',
                ]),
            );
        }

        // Seed $0 PlanPrice rows for BYO plans so priceForCycle() returns valid results
        foreach ($byoPlans as $byoPlan) {
            $plan = Plan::where('slug', $byoPlan['slug'])->first();
            foreach (['monthly', 'quarterly', 'semi_annual', 'annual'] as $cycle) {
                PlanPrice::updateOrCreate(
                    ['plan_id' => $plan->id, 'billing_cycle' => $cycle],
                    ['price' => 0.00],
                );
            }
        }
    }
}
