<?php

namespace Database\Seeders;

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

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $adminRoleId = Role::where('name', 'Admin')->value('id');
        $userRoleId = Role::where('name', 'User')->value('id');

        User::updateOrCreate(
            ['email' => 'admin@teste.com'],
            [
                'name' => 'Administrador Teste',
                'password' => Hash::make('password'),
                'role_id' => $adminRoleId ?? $userRoleId,
                'email_verified_at' => now(),
            ]
        );

        User::factory()
            ->count(200)
            ->state(function () use ($userRoleId, $adminRoleId) {
                return [
                    'role_id' => $userRoleId ?? $adminRoleId,
                ];
            })
            ->create();
    }
}
