<?php

use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\Models\Permission;

class AddLabCorePermissions extends Migration
{
    public function up()
    {
        $permissions = [
            'lab.access_module',
            'lab.manage_worklist',
            'lab.view_results',
            'lab.manage_results',
            'lab.manage_devices',
            'lab.manage_agents',
            'lab.view_logs',
            'lab.access_settings',
            'lab.superadmin',
        ];

        foreach ($permissions as $permission) {
            Permission::findOrCreate($permission, 'web');
        }
    }

    public function down()
    {
        $permissions = Permission::where('name', 'LIKE', 'lab.%')->get();
        foreach ($permissions as $permission) {
            $permission->delete();
        }
    }
}
