<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    public function up(): void
    {
        $ids = DB::table('permissions')
            ->where('slug', 'like', 'attendance.registration_form%')
            ->pluck('id')
            ->all();

        if ($ids === []) {
            return;
        }

        DB::table('role_permissions')->whereIn('permission_id', $ids)->delete();
        DB::table('permissions')->whereIn('id', $ids)->delete();
    }

    public function down(): void
    {
        // Non-destructive rollback: granular registration-form permissions are intentionally removed.
    }
};
