<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\DigitalMachine;
use App\Models\User;
use Illuminate\Support\Str;

/**
 * DigitalMachineSeeder
 *
 * Seeds 10 realistic digital health equipment listings.
 * All records are fully published and approved.
 *
 * Depends on: UserSeeder (Health Marketor and admin users must exist)
 */
class DigitalMachineSeeder extends Seeder
{
    public function run(): void
    {
        $marketor = User::where('email', 'healthmarketor@sshia.org')->first();
        $admin    = User::where('email', 'admin@sshia.org')->first();

        $userId     = $marketor?->id;
        $approvedBy = $admin?->id;

        $machines = [
            [
                'name'             => 'GE Voluson E10 Ultrasound System',
                'short_name'       => 'Voluson E10',
                'brand'            => 'GE Healthcare',
                'model'            => 'Voluson E10',
                'category'         => 'Imaging Equipment',
                'vendor'           => 'MedEquip South Sudan Ltd',
                'manufacturers'    => 'GE Healthcare, USA',
                'description'      => 'The GE Voluson E10 is a premium ultrasound system designed for women\'s health and fetal imaging. It delivers exceptional image quality with advanced 3D/4D capabilities, making it ideal for obstetric and gynecological examinations in South Sudan\'s leading hospitals.',
                'specifications'   => [
                    'Display'        => '21.5" HD LED monitor',
                    'Transducers'    => 'Up to 4 active transducer ports',
                    'Imaging Modes'  => 'B-mode, M-mode, Color Doppler, PW/CW Doppler, 3D/4D',
                    'Weight'         => '95 kg',
                    'Power Supply'   => '100-240V AC, 50/60Hz',
                    'Warranty'       => '2 years parts and labor',
                ],
                'functionalities'  => ['3D/4D Fetal Imaging', 'Color Doppler', 'Automated Measurements', 'DICOM Connectivity', 'Remote Diagnostics', 'Stress Echo'],
                'website_links'    => ['https://www.gehealthcare.com/products/ultrasound/voluson'],
                'contact_info'     => ['phone' => '+211 920 100 001', 'email' => 'sales@medequipss.com', 'whatsapp' => '+211 920 100 001'],
                'images'           => ['machines/ge-voluson-e10-main.jpg', 'machines/ge-voluson-e10-probe.jpg', 'machines/ge-voluson-e10-screen.jpg'],
                'video_clips'      => ['https://www.youtube.com/watch?v=voluson_demo'],
                'primary_image'    => 'machines/ge-voluson-e10-main.jpg',
                'price_ssp'        => 85000000.00,
                'price_usd'        => 65000.00,
                'price_publishable'=> true,
                'price_note'       => 'Price includes installation, training, and 2-year warranty. Financing options available.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 412,
                'inquiry_count'    => 28,
            ],
            [
                'name'             => 'Mindray BC-6800 Auto Hematology Analyzer',
                'short_name'       => 'BC-6800',
                'brand'            => 'Mindray',
                'model'            => 'BC-6800',
                'category'         => 'Laboratory Equipment',
                'vendor'           => 'LabTech Africa Distributors',
                'manufacturers'    => 'Mindray Medical International, China',
                'description'      => 'The Mindray BC-6800 is a fully automated 6-part differential hematology analyzer offering high throughput and reliable CBC results. Ideal for busy hospital laboratories in South Sudan requiring fast and accurate blood count analysis.',
                'specifications'   => [
                    'Parameters'     => '96 parameters including 6-part diff',
                    'Throughput'     => 'Up to 120 samples/hour',
                    'Sample Volume'  => '20 µL whole blood',
                    'Display'        => '10.4" color touch screen',
                    'Dimensions'     => '560 × 560 × 530 mm',
                    'Power'          => '100-240V AC, 50/60Hz',
                ],
                'functionalities'  => ['6-Part Differential', 'Reticulocyte Analysis', 'NRBC Detection', 'Auto Rerun', 'LIS Connectivity', 'QC Management'],
                'website_links'    => ['https://www.mindray.com/en/product/BC-6800.html'],
                'contact_info'     => ['phone' => '+211 920 100 002', 'email' => 'info@labtechafrica.ss', 'whatsapp' => '+211 920 100 002'],
                'images'           => ['machines/mindray-bc6800-main.jpg', 'machines/mindray-bc6800-screen.jpg'],
                'video_clips'      => [],
                'primary_image'    => 'machines/mindray-bc6800-main.jpg',
                'price_ssp'        => 12000000.00,
                'price_usd'        => 9200.00,
                'price_publishable'=> true,
                'price_note'       => 'Includes reagent starter pack and on-site installation.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 289,
                'inquiry_count'    => 19,
            ],
            [
                'name'             => 'Philips IntelliVue MX750 Patient Monitor',
                'short_name'       => 'IntelliVue MX750',
                'brand'            => 'Philips',
                'model'            => 'IntelliVue MX750',
                'category'         => 'Monitoring Devices',
                'vendor'           => 'Philips Healthcare East Africa',
                'manufacturers'    => 'Philips Healthcare, Netherlands',
                'description'      => 'The Philips IntelliVue MX750 is a high-acuity bedside patient monitor designed for ICU and critical care environments. It provides comprehensive monitoring of vital signs with advanced alarm management and seamless EMR integration.',
                'specifications'   => [
                    'Screen Size'    => '15" color display',
                    'Parameters'     => 'ECG, SpO2, NIBP, Temp, IBP, CO2',
                    'Battery Life'   => 'Up to 4 hours',
                    'Connectivity'   => 'Wi-Fi, Ethernet, Bluetooth',
                    'Weight'         => '6.5 kg',
                    'Standards'      => 'IEC 60601-1, CE marked',
                ],
                'functionalities'  => ['12-Lead ECG', 'Continuous SpO2', 'Capnography', 'Invasive Blood Pressure', 'Alarm Management', 'EMR Integration', 'Trending & Analytics'],
                'website_links'    => ['https://www.philips.com/healthcare/product/intellivue-mx750'],
                'contact_info'     => ['phone' => '+211 920 100 003', 'email' => 'healthcare.ss@philips.com'],
                'images'           => ['machines/philips-mx750-main.jpg', 'machines/philips-mx750-icu.jpg', 'machines/philips-mx750-display.jpg'],
                'video_clips'      => ['https://www.youtube.com/watch?v=intellivue_demo'],
                'primary_image'    => 'machines/philips-mx750-main.jpg',
                'price_ssp'        => 9800000.00,
                'price_usd'        => 7500.00,
                'price_publishable'=> true,
                'price_note'       => 'Bulk pricing available for orders of 5 or more units.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 356,
                'inquiry_count'    => 34,
            ],
            [
                'name'             => 'Siemens MAGNETOM Altea 1.5T MRI Scanner',
                'short_name'       => 'MAGNETOM Altea',
                'brand'            => 'Siemens Healthineers',
                'model'            => 'MAGNETOM Altea 1.5T',
                'category'         => 'Imaging Equipment',
                'vendor'           => 'Siemens Healthineers East Africa',
                'manufacturers'    => 'Siemens Healthineers, Germany',
                'description'      => 'The Siemens MAGNETOM Altea is a 1.5T MRI system offering outstanding image quality with a wide bore design for patient comfort. It is suitable for neurological, musculoskeletal, and abdominal imaging in South Sudan\'s major referral hospitals.',
                'specifications'   => [
                    'Field Strength' => '1.5 Tesla',
                    'Bore Diameter'  => '70 cm wide bore',
                    'Gradient'       => '33 mT/m amplitude, 125 T/m/s slew rate',
                    'Weight'         => '4,200 kg',
                    'Room Size'      => 'Minimum 40 m²',
                    'Power'          => '3-phase, 380-480V',
                ],
                'functionalities'  => ['Neuro Imaging', 'Cardiac MRI', 'Abdominal Imaging', 'MSK Imaging', 'AI-Powered Reconstruction', 'DICOM 3.0', 'Remote Service'],
                'website_links'    => ['https://www.siemens-healthineers.com/magnetic-resonance-imaging/1-5t-mri-scanner/magnetom-altea'],
                'contact_info'     => ['phone' => '+211 920 100 004', 'email' => 'mri.sales@siemens-healthineers.ss', 'whatsapp' => '+211 920 100 004'],
                'images'           => ['machines/siemens-altea-main.jpg', 'machines/siemens-altea-bore.jpg', 'machines/siemens-altea-console.jpg'],
                'video_clips'      => ['https://www.youtube.com/watch?v=magnetom_altea'],
                'primary_image'    => 'machines/siemens-altea-main.jpg',
                'price_ssp'        => null,
                'price_usd'        => null,
                'price_publishable'=> false,
                'price_note'       => 'Contact for custom quotation. Price includes site preparation consultation and installation.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 521,
                'inquiry_count'    => 47,
            ],
            [
                'name'             => 'Drager Fabius GS Premium Anesthesia Machine',
                'short_name'       => 'Fabius GS Premium',
                'brand'            => 'Dräger',
                'model'            => 'Fabius GS Premium',
                'category'         => 'Surgical Equipment',
                'vendor'           => 'MedEquip South Sudan Ltd',
                'manufacturers'    => 'Drägerwerk AG & Co. KGaA, Germany',
                'description'      => 'The Dräger Fabius GS Premium is a versatile anesthesia workstation designed for use in operating rooms across all surgical specialties. It combines reliable gas delivery with advanced ventilation modes and integrated patient monitoring.',
                'specifications'   => [
                    'Ventilation Modes' => 'IPPV, SIMV, PCV, CPAP, Manual',
                    'Tidal Volume'      => '20–1400 mL',
                    'Fresh Gas Flow'    => '0.2–15 L/min',
                    'Vaporizers'        => 'Up to 2 Dräger Vapor 2000',
                    'Display'           => '8.4" color touchscreen',
                    'Standards'         => 'ISO 80601-2-13, CE marked',
                ],
                'functionalities'  => ['Advanced Ventilation', 'Integrated Monitoring', 'Low-Flow Anesthesia', 'Agent Identification', 'Data Recording', 'Alarm Management'],
                'website_links'    => ['https://www.draeger.com/en_uk/Hospital/Anesthesia-Workstations/Fabius-GS-premium'],
                'contact_info'     => ['phone' => '+211 920 100 005', 'email' => 'sales@medequipss.com'],
                'images'           => ['machines/drager-fabius-main.jpg', 'machines/drager-fabius-controls.jpg'],
                'video_clips'      => [],
                'primary_image'    => 'machines/drager-fabius-main.jpg',
                'price_ssp'        => 32000000.00,
                'price_usd'        => 24500.00,
                'price_publishable'=> true,
                'price_note'       => 'Price includes installation, staff training, and 1-year preventive maintenance.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 198,
                'inquiry_count'    => 15,
            ],
            [
                'name'             => 'Roche Cobas 6000 Chemistry Analyzer',
                'short_name'       => 'Cobas 6000',
                'brand'            => 'Roche Diagnostics',
                'model'            => 'Cobas 6000',
                'category'         => 'Laboratory Equipment',
                'vendor'           => 'Roche Diagnostics East Africa',
                'manufacturers'    => 'Roche Diagnostics GmbH, Germany',
                'description'      => 'The Roche Cobas 6000 is a modular clinical chemistry and immunoassay analyzer offering high throughput and broad test menu. It is ideal for central laboratories in South Sudan requiring reliable biochemistry and immunology testing.',
                'specifications'   => [
                    'Throughput'     => 'Up to 2,000 photometric tests/hour',
                    'Test Menu'      => '100+ assays including immunoassay',
                    'Sample Volume'  => '2–35 µL',
                    'Calibration'    => 'Automatic multi-point calibration',
                    'Dimensions'     => '1,800 × 850 × 1,200 mm',
                    'Power'          => '200-240V AC, 50/60Hz',
                ],
                'functionalities'  => ['Clinical Chemistry', 'Immunoassay', 'Electrolytes', 'Auto Rerun', 'LIS/HIS Connectivity', 'Onboard Refrigeration', 'STAT Processing'],
                'website_links'    => ['https://diagnostics.roche.com/global/en/products/systems/cobas-6000-analyzer-series.html'],
                'contact_info'     => ['phone' => '+211 920 100 006', 'email' => 'diagnostics.ss@roche.com', 'whatsapp' => '+211 920 100 006'],
                'images'           => ['machines/roche-cobas6000-main.jpg', 'machines/roche-cobas6000-modules.jpg', 'machines/roche-cobas6000-screen.jpg'],
                'video_clips'      => ['https://www.youtube.com/watch?v=cobas6000_demo'],
                'primary_image'    => 'machines/roche-cobas6000-main.jpg',
                'price_ssp'        => 52000000.00,
                'price_usd'        => 40000.00,
                'price_publishable'=> true,
                'price_note'       => 'Reagent rental program available. Contact for details.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 334,
                'inquiry_count'    => 22,
            ],
            [
                'name'             => 'Carestream DRX-Evolution Plus Digital X-Ray',
                'short_name'       => 'DRX-Evolution Plus',
                'brand'            => 'Carestream Health',
                'model'            => 'DRX-Evolution Plus',
                'category'         => 'Diagnostic Equipment',
                'vendor'           => 'Imaging Solutions Africa',
                'manufacturers'    => 'Carestream Health Inc., USA',
                'description'      => 'The Carestream DRX-Evolution Plus is a versatile digital radiography system offering high-quality chest, skeletal, and abdominal imaging. Its wireless detector technology and intuitive workflow make it ideal for busy radiology departments in South Sudan.',
                'specifications'   => [
                    'Detector Size'  => '35 × 43 cm wireless DR detector',
                    'Resolution'     => '3.4 lp/mm',
                    'kVp Range'      => '40–150 kVp',
                    'mAs Range'      => '0.1–800 mAs',
                    'Image Display'  => '21" medical-grade monitor',
                    'Standards'      => 'IEC 60601-1, FDA cleared',
                ],
                'functionalities'  => ['Wireless DR Detector', 'Auto Exposure Control', 'DICOM 3.0', 'RIS/HIS Integration', 'Dose Management', 'Pediatric Protocols', 'Portable Detector'],
                'website_links'    => ['https://www.carestream.com/en/us/products/radiography/drx-evolution-plus.html'],
                'contact_info'     => ['phone' => '+211 920 100 007', 'email' => 'sales@imagingsolutionsafrica.ss'],
                'images'           => ['machines/carestream-drx-main.jpg', 'machines/carestream-drx-detector.jpg'],
                'video_clips'      => [],
                'primary_image'    => 'machines/carestream-drx-main.jpg',
                'price_ssp'        => 28000000.00,
                'price_usd'        => 21500.00,
                'price_publishable'=> true,
                'price_note'       => 'Includes PACS workstation and 3-year service contract.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 276,
                'inquiry_count'    => 18,
            ],
            [
                'name'             => 'Natus Neurology Nicolet EEG System',
                'short_name'       => 'Nicolet EEG',
                'brand'            => 'Natus Medical',
                'model'            => 'Nicolet v44',
                'category'         => 'Diagnostic Equipment',
                'vendor'           => 'Neuro Diagnostics Africa',
                'manufacturers'    => 'Natus Medical Incorporated, USA',
                'description'      => 'The Natus Nicolet v44 EEG system provides comprehensive electroencephalography for neurological diagnosis. It supports routine EEG, ambulatory monitoring, and ICU brain monitoring, making it essential for neurology departments in South Sudan.',
                'specifications'   => [
                    'Channels'       => '44 EEG channels',
                    'Sampling Rate'  => 'Up to 32,768 Hz',
                    'Input Impedance'=> '>100 MΩ',
                    'CMRR'           => '>110 dB',
                    'Battery Life'   => '8 hours (ambulatory mode)',
                    'Connectivity'   => 'USB, Wi-Fi, Ethernet',
                ],
                'functionalities'  => ['Routine EEG', 'Ambulatory EEG', 'ICU Monitoring', 'Video-EEG', 'Spike Detection', 'Seizure Analysis', 'Report Generation'],
                'website_links'    => ['https://www.natus.com/products/neurology/eeg'],
                'contact_info'     => ['phone' => '+211 920 100 008', 'email' => 'info@neurodiagnosticsafrica.ss', 'whatsapp' => '+211 920 100 008'],
                'images'           => ['machines/natus-eeg-main.jpg', 'machines/natus-eeg-electrodes.jpg', 'machines/natus-eeg-software.jpg'],
                'video_clips'      => ['https://www.youtube.com/watch?v=nicolet_eeg_demo'],
                'primary_image'    => 'machines/natus-eeg-main.jpg',
                'price_ssp'        => 18500000.00,
                'price_usd'        => 14200.00,
                'price_publishable'=> true,
                'price_note'       => 'Includes electrode caps, gel, and 2-day on-site training.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 143,
                'inquiry_count'    => 11,
            ],
            [
                'name'             => 'Stryker System 7 Surgical Power Tools',
                'short_name'       => 'System 7',
                'brand'            => 'Stryker',
                'model'            => 'System 7',
                'category'         => 'Surgical Equipment',
                'vendor'           => 'Surgical Supplies South Sudan',
                'manufacturers'    => 'Stryker Corporation, USA',
                'description'      => 'The Stryker System 7 is a comprehensive surgical power tool platform for orthopedic and general surgery. It offers a complete range of drills, saws, and reamers with a universal battery system, ideal for operating theaters in South Sudan.',
                'specifications'   => [
                    'Battery'        => '14.4V lithium-ion, autoclavable',
                    'Speed Range'    => '0–75,000 RPM (drill)',
                    'Torque'         => 'Up to 5.5 Nm',
                    'Sterilization'  => 'Steam autoclave compatible',
                    'Attachments'    => '20+ interchangeable attachments',
                    'Standards'      => 'ISO 13485, CE marked, FDA cleared',
                ],
                'functionalities'  => ['Orthopedic Drilling', 'Sagittal Sawing', 'Oscillating Sawing', 'Reaming', 'Wire Driving', 'Autoclavable Battery', 'Torque Control'],
                'website_links'    => ['https://www.stryker.com/us/en/portfolios/orthopaedics/surgical-power-tools/system-7.html'],
                'contact_info'     => ['phone' => '+211 920 100 009', 'email' => 'sales@surgicalsuppliess.ss'],
                'images'           => ['machines/stryker-system7-main.jpg', 'machines/stryker-system7-set.jpg'],
                'video_clips'      => [],
                'primary_image'    => 'machines/stryker-system7-main.jpg',
                'price_ssp'        => 15600000.00,
                'price_usd'        => 12000.00,
                'price_publishable'=> true,
                'price_note'       => 'Complete set includes drill, saw, reamer, and 2 batteries with charger.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 187,
                'inquiry_count'    => 14,
            ],
            [
                'name'             => 'Fresenius 5008S CorDiax Dialysis Machine',
                'short_name'       => '5008S CorDiax',
                'brand'            => 'Fresenius Medical Care',
                'model'            => '5008S CorDiax',
                'category'         => 'Therapeutic Equipment',
                'vendor'           => 'Renal Care Solutions Africa',
                'manufacturers'    => 'Fresenius Medical Care AG & Co. KGaA, Germany',
                'description'      => 'The Fresenius 5008S CorDiax is an advanced online hemodiafiltration machine offering superior dialysis quality for patients with chronic kidney disease. It is designed for dialysis centers and nephrology units in South Sudan\'s major hospitals.',
                'specifications'   => [
                    'Therapy Modes'  => 'HD, HDF, HF, UF, SLED',
                    'Blood Flow'     => '0–600 mL/min',
                    'Dialysate Flow' => '300–800 mL/min',
                    'UF Rate'        => '0–4,000 mL/h',
                    'Display'        => '12.1" color touchscreen',
                    'Standards'      => 'ISO 23500, CE marked',
                ],
                'functionalities'  => ['Online HDF', 'AutoSub', 'Blood Volume Monitoring', 'Kt/V Calculation', 'Temperature Control', 'Conductivity Monitoring', 'Data Management'],
                'website_links'    => ['https://www.freseniusmedicalcare.com/en/products/dialysis-machines/5008s-cordiax'],
                'contact_info'     => ['phone' => '+211 920 100 010', 'email' => 'info@renalcaresolutionsafrica.ss', 'whatsapp' => '+211 920 100 010'],
                'images'           => ['machines/fresenius-5008s-main.jpg', 'machines/fresenius-5008s-screen.jpg', 'machines/fresenius-5008s-dialysis.jpg'],
                'video_clips'      => ['https://www.youtube.com/watch?v=fresenius_5008s'],
                'primary_image'    => 'machines/fresenius-5008s-main.jpg',
                'price_ssp'        => 42000000.00,
                'price_usd'        => 32000.00,
                'price_publishable'=> true,
                'price_note'       => 'Price per unit. Consumables and water treatment system quoted separately.',
                'listing_status'   => 'published',
                'payment_status'   => 'paid',
                'is_published'     => true,
                'view_count'       => 298,
                'inquiry_count'    => 31,
            ],
        ];

        foreach ($machines as $data) {
            $name = $data['name'];

            // Idempotency: skip if already exists
            if (DigitalMachine::where('name', $name)->exists()) {
                $this->command->info("Skipping existing machine: {$name}");
                continue;
            }

            DigitalMachine::create(array_merge($data, [
                'user_id'      => $userId,
                'slug'         => Str::slug($name),
                'approved_by'  => $approvedBy,
                'approved_at'  => now()->subDays(rand(5, 60)),
                'published_at' => now()->subDays(rand(1, 90)),
                'expires_at'   => now()->addMonths(rand(3, 12)),
                'next_payment_date' => now()->addMonths(rand(3, 12)),
            ]));

            $this->command->info("Created machine: {$name}");
        }

        $this->command->info('DigitalMachineSeeder completed — 10 machines seeded.');
    }
}
