<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;

class UserSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Create superuser for testing
        DB::table('users')->updateOrInsert(
            ['email' => 'superuser@headroom.test'],
            [
                'id' => (string) Str::uuid(),
                'name' => 'Super User',
                'email' => 'superuser@headroom.test',
                'password' => Hash::make('password'),
                'role' => 'superuser',
                'created_at' => now(),
                'updated_at' => now(),
            ]
        );

        // Create test users for each role
        $testUsers = [
            [
                'name' => 'Manager User',
                'email' => 'manager@headroom.test',
                'role' => 'manager',
            ],
            [
                'name' => 'Developer User',
                'email' => 'developer@headroom.test',
                'role' => 'developer',
            ],
            [
                'name' => 'Top Brass User',
                'email' => 'topbrass@headroom.test',
                'role' => 'top_brass',
            ],
        ];

        foreach ($testUsers as $user) {
            DB::table('users')->updateOrInsert(
                ['email' => $user['email']],
                [
                    'id' => (string) Str::uuid(),
                    'name' => $user['name'],
                    'email' => $user['email'],
                    'password' => Hash::make('password'),
                    'role' => $user['role'],
                    'created_at' => now(),
                    'updated_at' => now(),
                ]
            );
        }
    }
}
