<?php

namespace Modules\MedNotify\Database\Seeders;

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

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