<?php

namespace Database\Seeders;

use App\Models\LocalizationManagement\City;
use App\Models\LocalizationManagement\Country;
use App\Models\LocalizationManagement\State;
use Illuminate\Database\Seeder;

class WorldStatusSeeder extends Seeder{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(){
        $countriesArray = ['Algeria', 'Bahrain', 'Djibouti', 'Egypt', 'Iraq', 'Jordan', 'Kuwait', 'Lebanon', 'Libya', 'Morocco', 'Mauritania', 'Oman', 'Palestinian', 'Territory Occupied', 'Qatar', 'Saudi Arabia', 'Sudan', 'Syria', 'Tunisia', 'Yemen'];

        Country::whereHas('states')->whereIn('name', $countriesArray)->update(['active' => true]);

        State::select('states.*')
            ->whereHas('cities')
            ->join('countries', 'states.country_id', '=', 'countries.id')
            ->where('countries.active', 1)
            ->update(['states.active' => true]);

        City::select('cities.*')
            ->join('states', 'cities.state_id', '=', 'states.id')
            ->where('states.active', 1)
            ->update(['cities.status' => true]);
    }
}
