<?php

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

/**
 * ClinicLab lab-upgrade permissions (SIFA P4-T4). Guard `web`, business-agnostic
 * Spatie permission rows (assigned to each business Admin# role by the
 * InstallController, and surfaced in the role editor via DataController).
 */
class AddClinicLabPermissions extends Migration
{
    public array $permissions = [
        'cliniclab.catalog.manage',
        'cliniclab.specimen.manage',
        'cliniclab.result.review',
        'cliniclab.result.verify',
        'cliniclab.outreach.manage',
    ];

    public function up(): void
    {
        foreach ($this->permissions as $permission) {
            Permission::findOrCreate($permission, 'web');
        }
    }

    public function down(): void
    {
        Permission::whereIn('name', $this->permissions)->where('guard_name', 'web')->delete();
    }
}
