<?php

declare(strict_types=1);

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Hash;

class UsersTableSeeder extends Seeder
{
    public function run(): void
    {
        $user = User::firstOrCreate(
            ['email' => 'morteza@mori.com'],
            [
                'first_name' => 'یوسف',
                'last_name' => 'روشندل',
                'cellphone' => '09210733936',
                'national_code' => '0012345678',
                'password' => Hash::make('123456789'),
                'wallet' => 15_500_000,
            ]
        );

        if (! $user->hasRole('user')) {
            $user->assignRole('user');
        }

        $user->updateQuietly([
            'wallet' => 15_500_000,
            'first_name' => 'یوسف',
            'last_name' => 'روشندل',
            'national_code' => '0012345678',
        ]);

        \Illuminate\Support\Facades\DB::table('users')
            ->where('id', $user->id)
            ->update(['wallet' => 15_500_000]);
    }
}
