<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
use Spatie\Permission\Models\Role;

class MikiAdminSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        // Crea o trova ruolo admin
        $adminRole = Role::firstOrCreate(['name' => 'admin']);
        $superAdminRole = Role::firstOrCreate(['name' => 'super-admin']);

        // Crea utente Miki Admin
        $mikiAdmin = User::updateOrCreate(
            ['email' => 'admin@example.com'],
            [
                'name' => 'Miki Admin',
                'email' => 'admin@example.com',
                'password' => Hash::make('password'),
                'email_verified_at' => now(),
            ]
        );

        // Assegna ruoli
        $mikiAdmin->assignRole(['admin', 'super-admin']);

        $this->command->info('✅ Utente Miki Admin creato/aggiornato:');
        $this->command->info('📧 Email: admin@example.com');
        $this->command->info('🔑 Password: password');
        $this->command->info('👤 Ruoli: admin, super-admin');
    }
}
