<?php

namespace Database\Seeders;

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

class AdminUserSeeder extends Seeder
{
    public function run(): void
    {
        // Create admin user with all permissions
        $admin = User::firstOrCreate([
            'email' => 'admin@creamy-utopia.com',
        ], [
            'name' => 'Administrator',
            'password' => bcrypt('123456'),
            'branch_id' => null,
        ]);

        // Assign super-admin role (which has all permissions)
        $admin->assignRole('super-admin');

        // Also directly sync all permissions for redundancy
        $admin->syncPermissions(Permission::all());

        $this->command->info('Admin user created: admin@creamy-utopia.com');
    }
}
