<?php

namespace App\Console\Commands;

use App\Models\PremiumFeature;
use Illuminate\Console\Command;

class ImportMecaprogramsPremiumFeatures extends Command
{
    protected $signature = 'mecaprograms:import-premium-features
        {--dry-run : Print what would be imported without saving}';

    protected $description = 'Import Premium Features section from mecaprograms.com';

    public function handle(): int
    {
        $this->info('Importing Premium Features...');

        $features = [
            [
                'title' => 'Multi-Brand Diagnostics',
                'description' => 'Comprehensive diagnostic coverage for light vehicles, heavy trucks, agricultural machinery, and industrial equipment from all major manufacturers worldwide.',
                'icon' => '&#9881;',
                'order' => 1,
            ],
            [
                'title' => 'ECU Calibration & Reprogramming',
                'description' => 'Advanced calibration and re-flashing capabilities for engine control units, transmission controllers, and vehicle electronic systems.',
                'icon' => '&#9889;',
                'order' => 2,
            ],
            [
                'title' => 'Parts Catalog Integration',
                'description' => 'Access to extensive OEM parts catalogs with exploded diagrams, part numbers, and cross-reference information for accurate spare parts identification.',
                'icon' => '&#128230;',
                'order' => 3,
            ],
            [
                'title' => 'Remote Support & Telematics',
                'description' => 'Secure remote access via TeamViewer and AnyDesk for real-time diagnostic support, calibration assistance, and software updates from anywhere.',
                'icon' => '&#128279;',
                'order' => 4,
            ],
            [
                'title' => 'Regular Software Updates',
                'description' => 'Stay current with the latest manufacturer software releases, protocol updates, and vehicle coverage expansions delivered regularly to your account.',
                'icon' => '&#128260;',
                'order' => 5,
            ],
            [
                'title' => 'Multi-Interface Support',
                'description' => 'Compatible with all major diagnostic interfaces including NEXIQ USB-Link, DPA5, DLA+2.0, DG VOCOM, and DrewTech adapters for flexible workshop setups.',
                'icon' => '&#128187;',
                'order' => 6,
            ],
        ];

        if ($this->option('dry-run')) {
            $this->table(['Title', 'Icon', 'Order'], array_map(fn($f) => [$f['title'], $f['icon'], $f['order']], $features));
            $this->info('Dry run complete. Nothing was saved.');
            return Command::SUCCESS;
        }

        PremiumFeature::truncate();

        foreach ($features as $data) {
            PremiumFeature::create($data);
            $this->line("  Created: {$data['title']}");
        }

        $this->info('Premium Features imported successfully.');

        return Command::SUCCESS;
    }
}
