<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $permissions = [
            ['name' => 'events.list', 'module' => 'events', 'action' => 'list'],
            ['name' => 'events.create', 'module' => 'events', 'action' => 'create'],
            ['name' => 'events.view', 'module' => 'events', 'action' => 'view'],
            ['name' => 'events.update', 'module' => 'events', 'action' => 'update'],
            ['name' => 'events.manage', 'module' => 'events', 'action' => 'manage'],
            ['name' => 'events.export', 'module' => 'events', 'action' => 'export'],
        ];

        foreach ($permissions as $perm) {
            DB::table('permissions')->insertOrIgnore([
                'name' => $perm['name'],
                'module' => $perm['module'],
                'action' => $perm['action'],
                'created_at' => now(),
            ]);
        }
    }

    public function down(): void
    {
        DB::table('permissions')->whereIn('name', [
            'events.list', 'events.create', 'events.view',
            'events.update', 'events.manage', 'events.export',
        ])->delete();
    }
};
