<?php

namespace Database\Seeders;

use App\Models\Permission;
use App\Models\Role;
use Illuminate\Database\Seeder;

class UserManagementPermissionSeeder extends Seeder
{
    /** @var array<string, string> */
    private const PERMISSIONS = [
        'user.view' => 'View users',
        'user.create' => 'Create users',
        'user.edit' => 'Edit users',
        'user.delete' => 'Delete users',
        'user.restore' => 'Restore users',
        'user.export' => 'Export users',
        'user.import' => 'Import users',
        'user.block' => 'Block or suspend users',
        'user.activate' => 'Activate users',
        'user.wallet' => 'Manage user wallets',
        'user.subscription' => 'Manage user subscriptions',
    ];

    public function run(): void
    {
        $permissionIds = collect(self::PERMISSIONS)->map(function (string $displayName, string $name): int {
            return Permission::query()->updateOrCreate(
                ['name' => $name],
                ['display_name' => $displayName, 'module' => 'users'],
            )->getKey();
        });

        Role::query()->where('name', 'super-admin')->first()?->permissions()->syncWithoutDetaching($permissionIds);
    }
}
