<?php

namespace Modules\MedWorkforce\Database\Seeders;

use Illuminate\Database\Seeder;
use Modules\MedWorkforce\Http\Controllers\DataController;
use Spatie\Permission\Models\Permission;

/**
 * Registers every medwf.* permission into the ERP RBAC (Spatie), idempotently.
 * The role editor surfaces these via DataController::user_permissions(); this
 * seeder + the register_medworkforce_permissions migration both guarantee the
 * rows exist so they can be assigned to roles. Mirrors MedbillPermissionSeeder.
 */
class MedwfPermissionSeeder extends Seeder
{
    public function run(): void
    {
        foreach ((new DataController)->user_permissions() as $perm) {
            Permission::firstOrCreate([
                'name'       => $perm['value'],
                'guard_name' => 'web',
            ]);
        }
    }
}
