<?php

namespace Database\Seeders;

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

class SimImeiPermissionSeeder extends Seeder
{
    /** @var array<string, string> */
    private const PERMISSIONS = [
        'sim.view' => 'View SIM information',
        'sim.manage' => 'Manage SIM records',
        'sim.history' => 'View SIM history',
        'imei.view' => 'View IMEI information',
        'imei.verify' => 'Verify device identities',
        'network.view' => 'View network status',
        'network.manage' => 'Manage network records',
        'reports.export' => 'Export recovery reports',
    ];

    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' => 'sim_imei'],
            )->getKey();
        });

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