<?php

namespace Database\Seeders;

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

class GovernoratesAndCitiesSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // إنشاء المحافظات
        $governorates = [
            ['id' => 1, 'name' => 'بغداد', 'created_at' => now(), 'updated_at' => now()],
            ['id' => 2, 'name' => 'البصرة', 'created_at' => now(), 'updated_at' => now()],
            ['id' => 3, 'name' => 'النجف', 'created_at' => now(), 'updated_at' => now()],
            ['id' => 4, 'name' => 'كربلاء', 'created_at' => now(), 'updated_at' => now()],
            ['id' => 5, 'name' => 'الأنبار', 'created_at' => now(), 'updated_at' => now()],
        ];

        foreach ($governorates as $governorate) {
            DB::table('governorates')->updateOrInsert(
                ['id' => $governorate['id']],
                $governorate
            );
        }

        // إنشاء المدن
        $cities = [
            ['id' => 1, 'name' => 'بغداد', 'governorate_id' => 1, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 2, 'name' => 'الكرادة', 'governorate_id' => 1, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 3, 'name' => 'الجادرية', 'governorate_id' => 1, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 4, 'name' => 'المنصور', 'governorate_id' => 1, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 5, 'name' => 'الأعظمية', 'governorate_id' => 1, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 6, 'name' => 'البصرة', 'governorate_id' => 2, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 7, 'name' => 'النجف', 'governorate_id' => 3, 'created_at' => now(), 'updated_at' => now()],
            ['id' => 8, 'name' => 'كربلاء', 'governorate_id' => 4, 'created_at' => now(), 'updated_at' => now()],
        ];

        foreach ($cities as $city) {
            DB::table('cities')->updateOrInsert(
                ['id' => $city['id']],
                $city
            );
        }

        echo "تم إنشاء " . count($governorates) . " محافظة و " . count($cities) . " مدينة\n";
    }
}
