<?php

namespace Database\Seeders;

use App\Models\User;
use Illuminate\Database\Seeder;

class TestUserSeeder extends Seeder
{
    public function run(): void
    {
        $email = 'field.tester@example.com';
        $password = 'password123';
        $name = 'Field Tester';

        // Create or update a predictable test user you can use to log in.
        $user = User::query()->firstOrCreate(
            ['email' => $email],
            [
                'name' => $name,
                // Will be auto-hashed by the User model cast.
                'password' => $password,
            ]
        );

        if (! $user->wasRecentlyCreated) {
            $user->name = $name;
            $user->password = $password; // auto-hashed by cast
        }

        if ($user->email_verified_at === null) {
            $user->email_verified_at = now();
        }

        $user->save();
    }
}
