<?php

declare(strict_types=1);

use App\Models\User;
use App\Models\Market\UserInfo;
use Hyperf\Database\Seeders\Seeder;
use Hypervel\Support\Str;

class UpdateUserInfoSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Find or create the test user Rex Moran Loba
        $user = User::where('email', 'rexm.loba@gmail.com')->first();
        
        if (!$user) {
            $user = User::create([
                'hashkey' => Str::random(64),
                'name' => 'Rex Loba',
                'fullname' => 'Rex Moran Loba',
                'email' => 'rexm.loba@gmail.com',
                'mobile_number' => '09123456789',
                'username' => 'rexl',
                'password' => 'password', // Hash should be handled by model or manually if not
                'acct_type' => 'user',
                'active' => true,
            ]);
        }

        $userInfo = UserInfo::where('user_id', $user->id)->first();
        
        if (!$userInfo) {
            $userInfo = new UserInfo([
                'user_id' => $user->id,
                'hashkey' => Str::random(64),
            ]);
        }

        $userInfo->fill([
            'firstname' => 'Rex Moran',
            'lastname' => 'Loba',
            'fullname' => 'Rex Moran Loba',
            'email' => 'rexm.loba@gmail.com',
            'mobile' => '09123456789',
            'civil_status' => 'Single',
            'education_level' => 'Bachelor\'s Degree',
            'livelihood_source' => 'Software Development',
            'is_active' => true,
        ]);

        $userInfo->save();
    }
}
