<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Governorate;
use App\Models\City;

class IraqiGovernoratesSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $governorates = [
            [
                'name_ar' => 'بغداد',
                'name_en' => 'Baghdad',
                'code' => 'BG',
                'latitude' => 33.3152,
                'longitude' => 44.3661,
                'sort_order' => 1,
                'cities' => [
                    ['name_ar' => 'بغداد', 'name_en' => 'Baghdad', 'latitude' => 33.3152, 'longitude' => 44.3661],
                    ['name_ar' => 'الكرخ', 'name_en' => 'Karkh', 'latitude' => 33.3152, 'longitude' => 44.3661],
                    ['name_ar' => 'الرصافة', 'name_en' => 'Rusafa', 'latitude' => 33.3152, 'longitude' => 44.3661],
                    ['name_ar' => 'المدائن', 'name_en' => 'Madain', 'latitude' => 33.3152, 'longitude' => 44.3661],
                ]
            ],
            [
                'name_ar' => 'البصرة',
                'name_en' => 'Basra',
                'code' => 'BS',
                'latitude' => 30.5088,
                'longitude' => 47.7804,
                'sort_order' => 2,
                'cities' => [
                    ['name_ar' => 'البصرة', 'name_en' => 'Basra', 'latitude' => 30.5088, 'longitude' => 47.7804],
                    ['name_ar' => 'الزبير', 'name_en' => 'Zubair', 'latitude' => 30.5088, 'longitude' => 47.7804],
                    ['name_ar' => 'أبو الخصيب', 'name_en' => 'Abu Al-Khasib', 'latitude' => 30.5088, 'longitude' => 47.7804],
                ]
            ],
            [
                'name_ar' => 'الموصل',
                'name_en' => 'Mosul',
                'code' => 'MS',
                'latitude' => 36.3350,
                'longitude' => 43.1189,
                'sort_order' => 3,
                'cities' => [
                    ['name_ar' => 'الموصل', 'name_en' => 'Mosul', 'latitude' => 36.3350, 'longitude' => 43.1189],
                    ['name_ar' => 'تلكيف', 'name_en' => 'Tel Keppe', 'latitude' => 36.3350, 'longitude' => 43.1189],
                    ['name_ar' => 'سنجار', 'name_en' => 'Sinjar', 'latitude' => 36.3350, 'longitude' => 43.1189],
                ]
            ],
            [
                'name_ar' => 'أربيل',
                'name_en' => 'Erbil',
                'code' => 'AR',
                'latitude' => 36.1911,
                'longitude' => 44.0092,
                'sort_order' => 4,
                'cities' => [
                    ['name_ar' => 'أربيل', 'name_en' => 'Erbil', 'latitude' => 36.1911, 'longitude' => 44.0092],
                    ['name_ar' => 'كويه', 'name_en' => 'Koya', 'latitude' => 36.1911, 'longitude' => 44.0092],
                    ['name_ar' => 'مخمور', 'name_en' => 'Makhmur', 'latitude' => 36.1911, 'longitude' => 44.0092],
                ]
            ],
            [
                'name_ar' => 'السليمانية',
                'name_en' => 'Sulaymaniyah',
                'code' => 'SU',
                'latitude' => 35.5578,
                'longitude' => 45.4321,
                'sort_order' => 5,
                'cities' => [
                    ['name_ar' => 'السليمانية', 'name_en' => 'Sulaymaniyah', 'latitude' => 35.5578, 'longitude' => 45.4321],
                    ['name_ar' => 'حلبجة', 'name_en' => 'Halabja', 'latitude' => 35.5578, 'longitude' => 45.4321],
                    ['name_ar' => 'قره داغ', 'name_en' => 'Qaradagh', 'latitude' => 35.5578, 'longitude' => 45.4321],
                ]
            ],
            [
                'name_ar' => 'دهوك',
                'name_en' => 'Dohuk',
                'code' => 'DH',
                'latitude' => 36.8667,
                'longitude' => 42.9833,
                'sort_order' => 6,
                'cities' => [
                    ['name_ar' => 'دهوك', 'name_en' => 'Dohuk', 'latitude' => 36.8667, 'longitude' => 42.9833],
                    ['name_ar' => 'زاخو', 'name_en' => 'Zakho', 'latitude' => 36.8667, 'longitude' => 42.9833],
                    ['name_ar' => 'عمادية', 'name_en' => 'Amadiya', 'latitude' => 36.8667, 'longitude' => 42.9833],
                ]
            ],
            [
                'name_ar' => 'الأنبار',
                'name_en' => 'Anbar',
                'code' => 'AN',
                'latitude' => 33.4206,
                'longitude' => 43.3075,
                'sort_order' => 7,
                'cities' => [
                    ['name_ar' => 'الرمادي', 'name_en' => 'Ramadi', 'latitude' => 33.4206, 'longitude' => 43.3075],
                    ['name_ar' => 'الفلوجة', 'name_en' => 'Fallujah', 'latitude' => 33.4206, 'longitude' => 43.3075],
                    ['name_ar' => 'هيت', 'name_en' => 'Hit', 'latitude' => 33.4206, 'longitude' => 43.3075],
                ]
            ],
            [
                'name_ar' => 'بابل',
                'name_en' => 'Babil',
                'code' => 'BB',
                'latitude' => 32.4826,
                'longitude' => 44.4329,
                'sort_order' => 8,
                'cities' => [
                    ['name_ar' => 'الحلة', 'name_en' => 'Hillah', 'latitude' => 32.4826, 'longitude' => 44.4329],
                    ['name_ar' => 'المسيب', 'name_en' => 'Musayyib', 'latitude' => 32.4826, 'longitude' => 44.4329],
                    ['name_ar' => 'المحمودية', 'name_en' => 'Mahmudiyah', 'latitude' => 32.4826, 'longitude' => 44.4329],
                ]
            ],
            [
                'name_ar' => 'كربلاء',
                'name_en' => 'Karbala',
                'code' => 'KB',
                'latitude' => 32.6160,
                'longitude' => 44.0249,
                'sort_order' => 9,
                'cities' => [
                    ['name_ar' => 'كربلاء', 'name_en' => 'Karbala', 'latitude' => 32.6160, 'longitude' => 44.0249],
                    ['name_ar' => 'عين التمر', 'name_en' => 'Ayn al-Tamr', 'latitude' => 32.6160, 'longitude' => 44.0249],
                ]
            ],
            [
                'name_ar' => 'النجف',
                'name_en' => 'Najaf',
                'code' => 'NJ',
                'latitude' => 31.9922,
                'longitude' => 44.3309,
                'sort_order' => 10,
                'cities' => [
                    ['name_ar' => 'النجف', 'name_en' => 'Najaf', 'latitude' => 31.9922, 'longitude' => 44.3309],
                    ['name_ar' => 'الكوفة', 'name_en' => 'Kufa', 'latitude' => 31.9922, 'longitude' => 44.3309],
                ]
            ],
            [
                'name_ar' => 'الديوانية',
                'name_en' => 'Diwaniyah',
                'code' => 'QA',
                'latitude' => 31.9892,
                'longitude' => 44.9249,
                'sort_order' => 11,
                'cities' => [
                    ['name_ar' => 'الديوانية', 'name_en' => 'Diwaniyah', 'latitude' => 31.9892, 'longitude' => 44.9249],
                    ['name_ar' => 'الشنافية', 'name_en' => 'Shanafiya', 'latitude' => 31.9892, 'longitude' => 44.9249],
                ]
            ],
            [
                'name_ar' => 'المثنى',
                'name_en' => 'Muthanna',
                'code' => 'MU',
                'latitude' => 31.3144,
                'longitude' => 45.2994,
                'sort_order' => 12,
                'cities' => [
                    ['name_ar' => 'السماوة', 'name_en' => 'Samawah', 'latitude' => 31.3144, 'longitude' => 45.2994],
                    ['name_ar' => 'الرطبة', 'name_en' => 'Rutba', 'latitude' => 31.3144, 'longitude' => 45.2994],
                ]
            ],
            [
                'name_ar' => 'القادسية',
                'name_en' => 'Qadisiyyah',
                'code' => 'QD',
                'latitude' => 32.0000,
                'longitude' => 45.0000,
                'sort_order' => 13,
                'cities' => [
                    ['name_ar' => 'الديوانية', 'name_en' => 'Diwaniyah', 'latitude' => 32.0000, 'longitude' => 45.0000],
                    ['name_ar' => 'الحمزة', 'name_en' => 'Hamza', 'latitude' => 32.0000, 'longitude' => 45.0000],
                ]
            ],
            [
                'name_ar' => 'واسط',
                'name_en' => 'Wasit',
                'code' => 'WA',
                'latitude' => 32.6160,
                'longitude' => 45.7500,
                'sort_order' => 14,
                'cities' => [
                    ['name_ar' => 'الكوت', 'name_en' => 'Kut', 'latitude' => 32.6160, 'longitude' => 45.7500],
                    ['name_ar' => 'الحي', 'name_en' => 'Al-Hay', 'latitude' => 32.6160, 'longitude' => 45.7500],
                ]
            ],
            [
                'name_ar' => 'ميسان',
                'name_en' => 'Maysan',
                'code' => 'MA',
                'latitude' => 31.8347,
                'longitude' => 47.0522,
                'sort_order' => 15,
                'cities' => [
                    ['name_ar' => 'العمارة', 'name_en' => 'Amarah', 'latitude' => 31.8347, 'longitude' => 47.0522],
                    ['name_ar' => 'المجر الكبير', 'name_en' => 'Majer al-Kabir', 'latitude' => 31.8347, 'longitude' => 47.0522],
                ]
            ],
            [
                'name_ar' => 'ذي قار',
                'name_en' => 'Dhi Qar',
                'code' => 'DQ',
                'latitude' => 31.0456,
                'longitude' => 46.2578,
                'sort_order' => 16,
                'cities' => [
                    ['name_ar' => 'الناصرية', 'name_en' => 'Nasiriyah', 'latitude' => 31.0456, 'longitude' => 46.2578],
                    ['name_ar' => 'الرفاعي', 'name_en' => 'Rifai', 'latitude' => 31.0456, 'longitude' => 46.2578],
                    ['name_ar' => 'الشطرة', 'name_en' => 'Shatra', 'latitude' => 31.0456, 'longitude' => 46.2578],
                ]
            ],
            [
                'name_ar' => 'صلاح الدين',
                'name_en' => 'Salah al-Din',
                'code' => 'SD',
                'latitude' => 34.4500,
                'longitude' => 43.5833,
                'sort_order' => 17,
                'cities' => [
                    ['name_ar' => 'تكريت', 'name_en' => 'Tikrit', 'latitude' => 34.4500, 'longitude' => 43.5833],
                    ['name_ar' => 'سامراء', 'name_en' => 'Samarra', 'latitude' => 34.4500, 'longitude' => 43.5833],
                    ['name_ar' => 'بيجي', 'name_en' => 'Baiji', 'latitude' => 34.4500, 'longitude' => 43.5833],
                ]
            ],
            [
                'name_ar' => 'كركوك',
                'name_en' => 'Kirkuk',
                'code' => 'KI',
                'latitude' => 35.4681,
                'longitude' => 44.3922,
                'sort_order' => 18,
                'cities' => [
                    ['name_ar' => 'كركوك', 'name_en' => 'Kirkuk', 'latitude' => 35.4681, 'longitude' => 44.3922],
                    ['name_ar' => 'داقوق', 'name_en' => 'Daquq', 'latitude' => 35.4681, 'longitude' => 44.3922],
                ]
            ]
        ];

        foreach ($governorates as $governorateData) {
            $cities = $governorateData['cities'];
            unset($governorateData['cities']);
            
            $governorate = Governorate::create($governorateData);
            
            foreach ($cities as $cityData) {
                $cityData['governorate_id'] = $governorate->id;
                $cityData['sort_order'] = 0;
                City::create($cityData);
            }
        }
    }
}
