<?php

namespace Database\Seeders;

use App\Models\LocalizationManagement\City;
use App\Models\LocalizationManagement\Country;
use App\Models\UserManagement\Customer;
use App\Models\UserManagement\User;
use App\Models\UserManagement\UserType;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Schema;

class UserAddressSeeder extends Seeder{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run(){
        Schema::disableForeignKeyConstraints();

        Customer::create([
            'first_name' => 'John',
            'last_name' => 'Do',
            'username' => 'ali',
            'email' => 'john@ali.com',
            'phone' => '0505050500',
            'password' => bcrypt('123456'),
            'email_verified_at' => now(),
        ]);

        $ali   = Customer::whereUsername('ali')->first();
        $ksa   = Country::with('states')->whereId(194)->first();
        $state = $ksa->states->random()->id;
        $city = City::whereStateId($state)->inRandomOrder()->first()->id;

        if ($ali){
            $ali->addresses()->create([
                'title'         => 'Home',
                'default'       => true,
                'first_name'            => 'Ali',
                'last_name'             => 'Al Qahtari',
                'email'                 => fake()->email,
                'phone'                => fake()->phoneNumber,
                'address'               => fake()->address,
                'address2'              => fake()->secondaryAddress,
                'country_id'            => $ksa->id,
                'state_id'              => $state,
                'city_id'               => $city,
                'zip_code'              => fake()->randomNumber(5),
                'po_box'                => fake()->randomNumber(4),
            ]);

            $ali->addresses()->create([
                'title'         => 'Work',
                'default'       => false,
                'first_name'            => 'Ali',
                'last_name'             => 'Al Qahtani',
                'email'                 => fake()->email,
                'phone'                => fake()->phoneNumber,
                'address'               => fake()->address,
                'address2'              => fake()->secondaryAddress,
                'country_id'            => 65,
                'state_id'              => 3223,
                'city_id'               => 31848,
                'zip_code'              => fake()->randomNumber(5),
                'po_box'                => fake()->randomNumber(4),
            ]);
        }



        Schema::enableForeignKeyConstraints();
    }
}
