<?php

namespace Database\Seeders;

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

class SuperAdminSeeder extends Seeder
{
    public function run(): void
    {
        $user = User::firstOrCreate(
            ['email' => 'pilkades@invitme.id'],
            [
                'name' => 'Super Admin Aldinara',
                'password' => Hash::make(str()->random(24)),
                'role' => 'super_admin',
                'is_active' => true,
                'email_verified_at' => now(),
            ]
        );

        $role = Role::where('name', 'super_admin')->first();

        if ($role) {
            $user->roles()->syncWithoutDetaching([$role->id]);
        }

        $this->command?->warn(
            "Super Admin seeded with email {$user->email}. Set/reset its password manually via `php artisan tinker` before first use — no plaintext password is seeded."
        );
    }
}
