<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;

class CountrySeeder extends Seeder
{
    public function run(): void
    {
        // continent_id matches ContinentSeeder IDs
        $countries = [
            // Africa (1)
            ['continent_id' => 1, 'name' => 'Nigeria',       'slug' => 'nigeria',       'flag_emoji' => '🇳🇬'],
            ['continent_id' => 1, 'name' => 'South Africa',  'slug' => 'south-africa',  'flag_emoji' => '🇿🇦'],
            ['continent_id' => 1, 'name' => 'Ghana',         'slug' => 'ghana',         'flag_emoji' => '🇬🇭'],
            ['continent_id' => 1, 'name' => 'Kenya',         'slug' => 'kenya',         'flag_emoji' => '🇰🇪'],
            ['continent_id' => 1, 'name' => 'Egypt',         'slug' => 'egypt',         'flag_emoji' => '🇪🇬'],

            // North America (2)
            ['continent_id' => 2, 'name' => 'United States', 'slug' => 'united-states', 'flag_emoji' => '🇺🇸'],
            ['continent_id' => 2, 'name' => 'Canada',        'slug' => 'canada',        'flag_emoji' => '🇨🇦'],
            ['continent_id' => 2, 'name' => 'Mexico',        'slug' => 'mexico',        'flag_emoji' => '🇲🇽'],

            // Europe (3)
            ['continent_id' => 3, 'name' => 'United Kingdom','slug' => 'united-kingdom','flag_emoji' => '🇬🇧'],
            ['continent_id' => 3, 'name' => 'France',        'slug' => 'france',        'flag_emoji' => '🇫🇷'],
            ['continent_id' => 3, 'name' => 'Germany',       'slug' => 'germany',       'flag_emoji' => '🇩🇪'],
            ['continent_id' => 3, 'name' => 'Spain',         'slug' => 'spain',         'flag_emoji' => '🇪🇸'],
            ['continent_id' => 3, 'name' => 'Italy',         'slug' => 'italy',         'flag_emoji' => '🇮🇹'],

            // Asia (4)
            ['continent_id' => 4, 'name' => 'India',         'slug' => 'india',         'flag_emoji' => '🇮🇳'],
            ['continent_id' => 4, 'name' => 'China',         'slug' => 'china',         'flag_emoji' => '🇨🇳'],
            ['continent_id' => 4, 'name' => 'Japan',         'slug' => 'japan',         'flag_emoji' => '🇯🇵'],
            ['continent_id' => 4, 'name' => 'Middle East',   'slug' => 'middle-east',   'flag_emoji' => '🌙'],

            // South America (5)
            ['continent_id' => 5, 'name' => 'Brazil',        'slug' => 'brazil',        'flag_emoji' => '🇧🇷'],
            ['continent_id' => 5, 'name' => 'Argentina',     'slug' => 'argentina',     'flag_emoji' => '🇦🇷'],
            ['continent_id' => 5, 'name' => 'Colombia',      'slug' => 'colombia',      'flag_emoji' => '🇨🇴'],

            // Oceania (6)
            ['continent_id' => 6, 'name' => 'Australia',     'slug' => 'australia',     'flag_emoji' => '🇦🇺'],
            ['continent_id' => 6, 'name' => 'New Zealand',   'slug' => 'new-zealand',   'flag_emoji' => '🇳🇿'],
        ];

        foreach ($countries as $country) {
            DB::table('countries')->updateOrInsert(
                ['slug' => $country['slug']],
                array_merge($country, [
                    'is_active'  => true,
                    'posts_count'=> 0,
                    'created_at' => now(),
                    'updated_at' => now(),
                ])
            );
        }

        $this->command->info('✓ Countries seeded (' . count($countries) . ')');
    }
}
