<?php

namespace Database\Seeders;

use App\Models\Permission;
use App\Models\Role;
use Illuminate\Database\Seeder;

class NotificationManagementPermissionSeeder extends Seeder
{
    /** @var array<string, string> */
    private const PERMISSIONS = [
        'notification.view' => 'View notifications',
        'notification.send' => 'Send notifications',
        'notification.broadcast' => 'Broadcast notifications',
        'notification.template' => 'Manage notification templates',
        'notification.logs' => 'View notification logs',
        'notification.analytics' => 'View notification analytics',
        'notification.settings' => 'Manage notification settings',
    ];

    public function run(): void
    {
        $permissionIds = collect(self::PERMISSIONS)->map(function (string $displayName, string $name): int {
            return Permission::query()->updateOrCreate(
                ['name' => $name],
                ['display_name' => $displayName, 'module' => 'notifications'],
            )->getKey();
        });

        Role::query()->where('name', 'super-admin')->first()?->permissions()->syncWithoutDetaching($permissionIds);
    }
}
