<?php

namespace Modules\MedDocuments\Database\Seeders;

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

/**
 * Registers every meddoc.* permission into the ERP RBAC (spatie permissions),
 * idempotently. The role editor already surfaces these via
 * DataController::user_permissions(); this seeder (plus the permissions
 * migration) guarantees the underlying permission rows exist so they can be
 * assigned to roles.
 *
 * Admins bypass these checks via the core Gate::before for Admin#<business_id>.
 */
class MeddocPermissionSeeder extends Seeder
{
    public function run(): void
    {
        foreach ((new DataController)->user_permissions() as $perm) {
            Permission::firstOrCreate([
                'name'       => $perm['value'],
                'guard_name' => 'web',
            ]);
        }
    }
}
