<?php

namespace Database\Seeders;

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

class PermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {
        $permissions = [
            // PRC-1070: legacy 'admin.X' menü-izinleri KALDIRILDI (hiçbir route/blade/controller
            // kullanmıyordu — dead). Kanonik şema: 'view|create|update|delete {kaynak}'.

            // Client permissions
            ['name' => 'client.dashboard', 'guard_name' => 'web'],
            ['name' => 'client.profile', 'guard_name' => 'web'],
            ['name' => 'client.products', 'guard_name' => 'web'],
            ['name' => 'client.orders', 'guard_name' => 'web'],
            ['name' => 'client.invoices', 'guard_name' => 'web'],
            ['name' => 'client.tickets', 'guard_name' => 'web'],

            // Clients permissions
            ['name' => 'view clients', 'guard_name' => 'admin'],
            ['name' => 'create clients', 'guard_name' => 'admin'],
            ['name' => 'update clients', 'guard_name' => 'admin'],
            ['name' => 'delete clients', 'guard_name' => 'admin'],
            // PRC-202: SEC-Critical — impersonate dedicated permission (super-admin only)
            ['name' => 'impersonate clients', 'guard_name' => 'admin'],

            // Product permissions
            ['name' => 'view products', 'guard_name' => 'admin'],
            ['name' => 'create products', 'guard_name' => 'admin'],
            ['name' => 'update products', 'guard_name' => 'admin'],
            ['name' => 'delete products', 'guard_name' => 'admin'],
            ['name' => 'view product change failures', 'guard_name' => 'admin'],

            // Product category permissions
            ['name' => 'view product categories', 'guard_name' => 'admin'],
            ['name' => 'create product categories', 'guard_name' => 'admin'],
            ['name' => 'update product categories', 'guard_name' => 'admin'],
            ['name' => 'delete product categories', 'guard_name' => 'admin'],

            // Product group permissions
            ['name' => 'view product groups', 'guard_name' => 'admin'],
            ['name' => 'create product groups', 'guard_name' => 'admin'],
            ['name' => 'update product groups', 'guard_name' => 'admin'],
            ['name' => 'delete product groups', 'guard_name' => 'admin'],

            // Product config option permissions
            ['name' => 'view product config options', 'guard_name' => 'admin'],
            ['name' => 'create product config options', 'guard_name' => 'admin'],
            ['name' => 'update product config options', 'guard_name' => 'admin'],
            ['name' => 'delete product config options', 'guard_name' => 'admin'],
            ['name' => 'restore product config options', 'guard_name' => 'admin'],
            ['name' => 'force delete product config options', 'guard_name' => 'admin'],

            // 3rd-party license permissions — PRC-60
            ['name' => 'view licenses', 'guard_name' => 'admin'],
            ['name' => 'manage licenses', 'guard_name' => 'admin'],

            // Product config option group permissions
            ['name' => 'view product config option groups', 'guard_name' => 'admin'],
            ['name' => 'create product config option groups', 'guard_name' => 'admin'],
            ['name' => 'update product config option groups', 'guard_name' => 'admin'],
            ['name' => 'delete product config option groups', 'guard_name' => 'admin'],
            ['name' => 'restore product config option groups', 'guard_name' => 'admin'],
            ['name' => 'force delete product config option groups', 'guard_name' => 'admin'],

            // Order permissions
            ['name' => 'view orders', 'guard_name' => 'admin'],
            ['name' => 'create orders', 'guard_name' => 'admin'],
            ['name' => 'update orders', 'guard_name' => 'admin'],
            ['name' => 'delete orders', 'guard_name' => 'admin'],

            // Billing permissions
            ['name' => 'view invoices', 'guard_name' => 'admin'],
            ['name' => 'create invoices', 'guard_name' => 'admin'],
            ['name' => 'update invoices', 'guard_name' => 'admin'],
            ['name' => 'delete invoices', 'guard_name' => 'admin'],
            ['name' => 'process invoice payments', 'guard_name' => 'admin'],
            ['name' => 'cancel invoices', 'guard_name' => 'admin'],
            ['name' => 'add late fees', 'guard_name' => 'admin'],
            ['name' => 'add grace period fees', 'guard_name' => 'admin'],
            ['name' => 'add redemption fees', 'guard_name' => 'admin'],
            ['name' => 'recalculate invoices', 'guard_name' => 'admin'],
            ['name' => 'download invoice pdfs', 'guard_name' => 'admin'],
            ['name' => 'manage billing rules', 'guard_name' => 'admin'],
            ['name' => 'manage blocked_domain_patterns', 'guard_name' => 'admin'],
            ['name' => 'manage provisioning queue', 'guard_name' => 'admin'],
            ['name' => 'manage dns zones', 'guard_name' => 'admin'],

            // Transaction permissions
            ['name' => 'view transactions', 'guard_name' => 'admin'],
            ['name' => 'create transactions', 'guard_name' => 'admin'],
            ['name' => 'update transactions', 'guard_name' => 'admin'],
            ['name' => 'delete transactions', 'guard_name' => 'admin'],

            // Reports permissions
            ['name' => 'view reports', 'guard_name' => 'admin'],
            ['name' => 'generate reports', 'guard_name' => 'admin'],
            ['name' => 'export reports', 'guard_name' => 'admin'],

            // Custom reports (PRC-24)
            ['name' => 'view custom reports', 'guard_name' => 'admin'],
            ['name' => 'create custom reports', 'guard_name' => 'admin'],
            ['name' => 'manage custom reports', 'guard_name' => 'admin'],
            // PRC-38 — Separate gate for CSV export to prevent bulk exfiltration via view-only role
            ['name' => 'export custom reports', 'guard_name' => 'admin'],

            // TLD permissions
            ['name' => 'view tlds', 'guard_name' => 'admin'],
            ['name' => 'create tlds', 'guard_name' => 'admin'],
            ['name' => 'update tlds', 'guard_name' => 'admin'],
            ['name' => 'delete tlds', 'guard_name' => 'admin'],

            // Log permissions
            ['name' => 'view logs', 'guard_name' => 'admin'],
            ['name' => 'create logs', 'guard_name' => 'admin'],
            ['name' => 'update logs', 'guard_name' => 'admin'],
            ['name' => 'delete logs', 'guard_name' => 'admin'],
            ['name' => 'restore logs', 'guard_name' => 'admin'],
            ['name' => 'force delete logs', 'guard_name' => 'admin'],
            ['name' => 'view admin logs', 'guard_name' => 'admin'],

            // Queue Management permissions
            ['name' => 'view queue', 'guard_name' => 'admin'],
            ['name' => 'manage queue', 'guard_name' => 'admin'],

            // Verification permissions
            ['name' => 'view verifications', 'guard_name' => 'admin'],
            ['name' => 'approve verifications', 'guard_name' => 'admin'],

            // Server permissions
            ['name' => 'view servers', 'guard_name' => 'admin'],
            ['name' => 'create servers', 'guard_name' => 'admin'],
            ['name' => 'update servers', 'guard_name' => 'admin'],
            ['name' => 'delete servers', 'guard_name' => 'admin'],
            // PRC-817 — fiziksel sunucu envanteri (datacenter/rack)
            ['name' => 'view datacenters', 'guard_name' => 'admin'],
            ['name' => 'create datacenters', 'guard_name' => 'admin'],
            ['name' => 'update datacenters', 'guard_name' => 'admin'],
            ['name' => 'delete datacenters', 'guard_name' => 'admin'],
            ['name' => 'view racks', 'guard_name' => 'admin'],
            ['name' => 'create racks', 'guard_name' => 'admin'],
            ['name' => 'update racks', 'guard_name' => 'admin'],
            ['name' => 'delete racks', 'guard_name' => 'admin'],

            // Server Group permissions
            ['name' => 'view server groups', 'guard_name' => 'admin'],
            ['name' => 'create server groups', 'guard_name' => 'admin'],
            ['name' => 'update server groups', 'guard_name' => 'admin'],
            ['name' => 'delete server groups', 'guard_name' => 'admin'],

            // IP Pool permissions
            ['name' => 'view ip pools', 'guard_name' => 'admin'],
            ['name' => 'create ip pools', 'guard_name' => 'admin'],
            ['name' => 'update ip pools', 'guard_name' => 'admin'],
            ['name' => 'delete ip pools', 'guard_name' => 'admin'],
            ['name' => 'manage ip allocations', 'guard_name' => 'admin'],

            // Ticket permissions
            ['name' => 'view tickets', 'guard_name' => 'admin'],
            ['name' => 'create tickets', 'guard_name' => 'admin'],
            ['name' => 'update tickets', 'guard_name' => 'admin'],
            ['name' => 'delete tickets', 'guard_name' => 'admin'],
            ['name' => 'reply tickets', 'guard_name' => 'admin'],
            ['name' => 'merge tickets', 'guard_name' => 'admin'],

            // Workflow permissions (PRC-26)
            ['name' => 'view workflows', 'guard_name' => 'admin'],
            ['name' => 'manage workflows', 'guard_name' => 'admin'],

            // Ticket Predefined Reply permissions
            ['name' => 'view ticket predefined replies', 'guard_name' => 'admin'],
            ['name' => 'create ticket predefined replies', 'guard_name' => 'admin'],
            ['name' => 'update ticket predefined replies', 'guard_name' => 'admin'],
            ['name' => 'delete ticket predefined replies', 'guard_name' => 'admin'],

            // AI Staff permissions
            ['name' => 'view ai staff', 'guard_name' => 'admin'],
            ['name' => 'create ai staff', 'guard_name' => 'admin'],
            ['name' => 'update ai staff', 'guard_name' => 'admin'],
            ['name' => 'delete ai staff', 'guard_name' => 'admin'],

            // AI Training permissions
            ['name' => 'view ai training', 'guard_name' => 'admin'],
            ['name' => 'create ai training', 'guard_name' => 'admin'],
            ['name' => 'update ai training', 'guard_name' => 'admin'],
            ['name' => 'delete ai training', 'guard_name' => 'admin'],

            // System Management - Admin Management permissions
            ['name' => 'view admin management', 'guard_name' => 'admin'],
            ['name' => 'create admin management', 'guard_name' => 'admin'],
            ['name' => 'update admin management', 'guard_name' => 'admin'],
            ['name' => 'delete admin management', 'guard_name' => 'admin'],

            // System Management - Role Management permissions
            ['name' => 'view role management', 'guard_name' => 'admin'],
            ['name' => 'create role management', 'guard_name' => 'admin'],
            ['name' => 'update role management', 'guard_name' => 'admin'],
            ['name' => 'delete role management', 'guard_name' => 'admin'],

            // System Management - Permission Management permissions
            ['name' => 'view permission management', 'guard_name' => 'admin'],
            ['name' => 'create permission management', 'guard_name' => 'admin'],
            ['name' => 'update permission management', 'guard_name' => 'admin'],
            ['name' => 'delete permission management', 'guard_name' => 'admin'],

            // Service Cost permissions
            ['name' => 'view service costs', 'guard_name' => 'admin'],
            ['name' => 'create service costs', 'guard_name' => 'admin'],
            ['name' => 'update service costs', 'guard_name' => 'admin'],
            ['name' => 'delete service costs', 'guard_name' => 'admin'],
            ['name' => 'restore service costs', 'guard_name' => 'admin'],
            ['name' => 'force delete service costs', 'guard_name' => 'admin'],

            // Domain Cost permissions
            ['name' => 'view domain costs', 'guard_name' => 'admin'],
            ['name' => 'create domain costs', 'guard_name' => 'admin'],
            ['name' => 'update domain costs', 'guard_name' => 'admin'],
            ['name' => 'delete domain costs', 'guard_name' => 'admin'],
            ['name' => 'restore domain costs', 'guard_name' => 'admin'],
            ['name' => 'force delete domain costs', 'guard_name' => 'admin'],

            // TODO(unified-posts Phase 12): replace with `view posts`, `manage posts`, `manage tags` after PostController + TagController land.
            // Knowledge Base Category permissions
            ['name' => 'view knowledgebase categories', 'guard_name' => 'admin'],
            ['name' => 'create knowledgebase categories', 'guard_name' => 'admin'],
            ['name' => 'update knowledgebase categories', 'guard_name' => 'admin'],
            ['name' => 'delete knowledgebase categories', 'guard_name' => 'admin'],

            // TODO(unified-posts Phase 12): replace with `view posts`, `manage posts`, `manage tags` after PostController + TagController land.
            // Knowledge Base Article permissions
            ['name' => 'view knowledgebase articles', 'guard_name' => 'admin'],
            ['name' => 'create knowledgebase articles', 'guard_name' => 'admin'],
            ['name' => 'update knowledgebase articles', 'guard_name' => 'admin'],
            ['name' => 'delete knowledgebase articles', 'guard_name' => 'admin'],

            // Tax Rule permissions
            ['name' => 'view tax rules', 'guard_name' => 'admin'],
            ['name' => 'create tax rules', 'guard_name' => 'admin'],
            ['name' => 'update tax rules', 'guard_name' => 'admin'],
            ['name' => 'delete tax rules', 'guard_name' => 'admin'],

            // Email Marketing permissions
            ['name' => 'view email marketing', 'guard_name' => 'admin'],
            ['name' => 'create email marketing', 'guard_name' => 'admin'],
            ['name' => 'update email marketing', 'guard_name' => 'admin'],
            ['name' => 'delete email marketing', 'guard_name' => 'admin'],
            ['name' => 'manage email marketing subscribers', 'guard_name' => 'admin'],
            ['name' => 'send email campaigns', 'guard_name' => 'admin'],

            // PRC-796 — İYS (İleti Yönetim Sistemi) permissions
            ['name' => 'view iys', 'guard_name' => 'admin'],
            ['name' => 'manage iys', 'guard_name' => 'admin'],

            // Email Campaign permissions
            ['name' => 'view email campaigns', 'guard_name' => 'admin'],
            ['name' => 'create email campaigns', 'guard_name' => 'admin'],
            ['name' => 'update email campaigns', 'guard_name' => 'admin'],
            ['name' => 'delete email campaigns', 'guard_name' => 'admin'],

            // Quote permissions
            ['name' => 'view quotes', 'guard_name' => 'admin'],
            ['name' => 'create quotes', 'guard_name' => 'admin'],
            ['name' => 'update quotes', 'guard_name' => 'admin'],
            ['name' => 'delete quotes', 'guard_name' => 'admin'],

            // Client Balance permissions
            ['name' => 'view client balances', 'guard_name' => 'admin'],
            ['name' => 'create client balances', 'guard_name' => 'admin'],
            ['name' => 'update client balances', 'guard_name' => 'admin'],
            ['name' => 'delete client balances', 'guard_name' => 'admin'],
            ['name' => 'add client balance', 'guard_name' => 'admin'],
            ['name' => 'deduct client balance', 'guard_name' => 'admin'],
            ['name' => 'process client payout', 'guard_name' => 'admin'],
            ['name' => 'process client refund', 'guard_name' => 'admin'],

            // Menu permissions
            ['name' => 'manage menus', 'guard_name' => 'admin'],

            // Page builder permissions
            ['name' => 'manage pages', 'guard_name' => 'admin'],

            // RBAC coverage (PRC-227/231/236/178/185)
            ['name' => 'view billing', 'guard_name' => 'admin'],
            ['name' => 'manage billing', 'guard_name' => 'admin'],
            ['name' => 'view system management', 'guard_name' => 'admin'],
            ['name' => 'manage system management', 'guard_name' => 'admin'],
            ['name' => 'manage api tokens', 'guard_name' => 'admin'],

            // PRC-398 / PRC-327 — Module Management UI permissions
            ['name' => 'manage modules', 'guard_name' => 'admin'],
            ['name' => 'manage sms modules', 'guard_name' => 'admin'],
            ['name' => 'manage email modules', 'guard_name' => 'admin'],
            ['name' => 'manage citizenship modules', 'guard_name' => 'admin'],
            ['name' => 'manage dns providers', 'guard_name' => 'admin'],
            ['name' => 'manage currency providers', 'guard_name' => 'admin'],

            // PRC-1068 — SSL certificate management + reseller manual-install backstop
            ['name' => 'view ssl certificates', 'guard_name' => 'admin'],
            ['name' => 'manage ssl certificates', 'guard_name' => 'admin'],

            // PRC-1070 Faz B — daha önce TAMAMEN ungated kaynakların yeni kanonik izinleri
            ['name' => 'create brands', 'guard_name' => 'admin'],
            ['name' => 'create client discounts', 'guard_name' => 'admin'],
            ['name' => 'create client groups', 'guard_name' => 'admin'],
            ['name' => 'create contracts', 'guard_name' => 'admin'],
            ['name' => 'create downloads', 'guard_name' => 'admin'],
            ['name' => 'create resellers', 'guard_name' => 'admin'],
            ['name' => 'create sla plans', 'guard_name' => 'admin'],
            ['name' => 'delete brands', 'guard_name' => 'admin'],
            ['name' => 'delete client discounts', 'guard_name' => 'admin'],
            ['name' => 'delete client groups', 'guard_name' => 'admin'],
            ['name' => 'delete contracts', 'guard_name' => 'admin'],
            ['name' => 'delete downloads', 'guard_name' => 'admin'],
            ['name' => 'delete resellers', 'guard_name' => 'admin'],
            ['name' => 'delete sla plans', 'guard_name' => 'admin'],
            ['name' => 'manage fraud', 'guard_name' => 'admin'],
            ['name' => 'update brands', 'guard_name' => 'admin'],
            ['name' => 'update client discounts', 'guard_name' => 'admin'],
            ['name' => 'update client groups', 'guard_name' => 'admin'],
            ['name' => 'update contracts', 'guard_name' => 'admin'],
            ['name' => 'update downloads', 'guard_name' => 'admin'],
            ['name' => 'update resellers', 'guard_name' => 'admin'],
            ['name' => 'update sla plans', 'guard_name' => 'admin'],
            ['name' => 'view announcements', 'guard_name' => 'admin'],
            ['name' => 'view blog', 'guard_name' => 'admin'],
            ['name' => 'view brands', 'guard_name' => 'admin'],
            ['name' => 'view client discounts', 'guard_name' => 'admin'],
            ['name' => 'view client groups', 'guard_name' => 'admin'],
            ['name' => 'view contracts', 'guard_name' => 'admin'],
            ['name' => 'view downloads', 'guard_name' => 'admin'],
            ['name' => 'view fraud', 'guard_name' => 'admin'],
            ['name' => 'delete licenses', 'guard_name' => 'admin'],
            ['name' => 'view resellers', 'guard_name' => 'admin'],
            ['name' => 'view sla plans', 'guard_name' => 'admin'],

            // PRC-1070 — tek-kaynak: AdminSeeder'da tanımlı olup PermissionSeeder'da eksik olanlar
            ['name' => 'assign permissions', 'guard_name' => 'admin'],
            ['name' => 'create email templates', 'guard_name' => 'admin'],
            ['name' => 'create notification templates', 'guard_name' => 'admin'],
            ['name' => 'create roles', 'guard_name' => 'admin'],
            ['name' => 'create sms templates', 'guard_name' => 'admin'],
            ['name' => 'create users', 'guard_name' => 'admin'],
            ['name' => 'delete notification templates', 'guard_name' => 'admin'],
            ['name' => 'delete roles', 'guard_name' => 'admin'],
            ['name' => 'delete sms templates', 'guard_name' => 'admin'],
            ['name' => 'delete users', 'guard_name' => 'admin'],
            ['name' => 'manage addon-modules', 'guard_name' => 'admin'],
            ['name' => 'update email templates', 'guard_name' => 'admin'],
            ['name' => 'update notification templates', 'guard_name' => 'admin'],
            ['name' => 'update sms templates', 'guard_name' => 'admin'],
            ['name' => 'view email templates', 'guard_name' => 'admin'],
            ['name' => 'view notification templates', 'guard_name' => 'admin'],
            ['name' => 'view roles', 'guard_name' => 'admin'],
            ['name' => 'view sms templates', 'guard_name' => 'admin'],
            ['name' => 'view support banners', 'guard_name' => 'admin'],
            ['name' => 'view users', 'guard_name' => 'admin'],

            // PRC-1070 — kanonik izin boşluğu kapatma (kodda enforce edilen ama seed edilmeyen 89 izin)
            ['name' => 'approve cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'cancel cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'cleanup baskets', 'guard_name' => 'admin'],
            ['name' => 'create baskets', 'guard_name' => 'admin'],
            ['name' => 'create cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'create client custom fields', 'guard_name' => 'admin'],
            ['name' => 'create coupons', 'guard_name' => 'admin'],
            ['name' => 'create escalation rules', 'guard_name' => 'admin'],
            ['name' => 'create expenses', 'guard_name' => 'admin'],
            ['name' => 'create invoice billings', 'guard_name' => 'admin'],
            ['name' => 'create languages', 'guard_name' => 'admin'],
            ['name' => 'create payment gateways', 'guard_name' => 'admin'],
            ['name' => 'create promotions', 'guard_name' => 'admin'],
            ['name' => 'create recurring expenses', 'guard_name' => 'admin'],
            ['name' => 'create registrars', 'guard_name' => 'admin'],
            ['name' => 'create ticket departments', 'guard_name' => 'admin'],
            ['name' => 'create ticket statuses', 'guard_name' => 'admin'],
            ['name' => 'delete baskets', 'guard_name' => 'admin'],
            ['name' => 'delete cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'delete client custom fields', 'guard_name' => 'admin'],
            ['name' => 'delete coupons', 'guard_name' => 'admin'],
            ['name' => 'delete escalation rules', 'guard_name' => 'admin'],
            ['name' => 'delete expenses', 'guard_name' => 'admin'],
            ['name' => 'delete invoice billings', 'guard_name' => 'admin'],
            ['name' => 'delete languages', 'guard_name' => 'admin'],
            ['name' => 'delete payment gateways', 'guard_name' => 'admin'],
            ['name' => 'delete promotions', 'guard_name' => 'admin'],
            ['name' => 'delete recurring expenses', 'guard_name' => 'admin'],
            ['name' => 'delete registrars', 'guard_name' => 'admin'],
            ['name' => 'delete ticket departments', 'guard_name' => 'admin'],
            ['name' => 'delete ticket statuses', 'guard_name' => 'admin'],
            ['name' => 'edit clients', 'guard_name' => 'admin'],
            ['name' => 'force delete baskets', 'guard_name' => 'admin'],
            ['name' => 'force delete clients', 'guard_name' => 'admin'],
            ['name' => 'force delete coupons', 'guard_name' => 'admin'],
            ['name' => 'force delete payment gateways', 'guard_name' => 'admin'],
            ['name' => 'force delete promotions', 'guard_name' => 'admin'],
            ['name' => 'force delete ticket predefined replies', 'guard_name' => 'admin'],
            ['name' => 'manage affiliates', 'guard_name' => 'admin'],
            ['name' => 'manage backups', 'guard_name' => 'admin'],
            ['name' => 'manage blocked', 'guard_name' => 'admin'],
            ['name' => 'manage expense settings', 'guard_name' => 'admin'],
            ['name' => 'manage settings', 'guard_name' => 'admin'],
            ['name' => 'manage support banners', 'guard_name' => 'admin'],
            ['name' => 'reject cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'restore baskets', 'guard_name' => 'admin'],
            ['name' => 'restore clients', 'guard_name' => 'admin'],
            ['name' => 'restore coupons', 'guard_name' => 'admin'],
            ['name' => 'restore payment gateways', 'guard_name' => 'admin'],
            ['name' => 'restore promotions', 'guard_name' => 'admin'],
            ['name' => 'restore ticket predefined replies', 'guard_name' => 'admin'],
            ['name' => 'update baskets', 'guard_name' => 'admin'],
            ['name' => 'update cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'update client custom fields', 'guard_name' => 'admin'],
            ['name' => 'update coupons', 'guard_name' => 'admin'],
            ['name' => 'update currencies', 'guard_name' => 'admin'],
            ['name' => 'update escalation rules', 'guard_name' => 'admin'],
            ['name' => 'update expenses', 'guard_name' => 'admin'],
            ['name' => 'update invoice billings', 'guard_name' => 'admin'],
            ['name' => 'update languages', 'guard_name' => 'admin'],
            ['name' => 'update payment gateways', 'guard_name' => 'admin'],
            ['name' => 'update promotions', 'guard_name' => 'admin'],
            ['name' => 'update recurring expenses', 'guard_name' => 'admin'],
            ['name' => 'update registrars', 'guard_name' => 'admin'],
            ['name' => 'update tax settings', 'guard_name' => 'admin'],
            ['name' => 'update ticket departments', 'guard_name' => 'admin'],
            ['name' => 'update ticket statuses', 'guard_name' => 'admin'],
            ['name' => 'use network tools', 'guard_name' => 'admin'],
            ['name' => 'view affiliates', 'guard_name' => 'admin'],
            ['name' => 'view basket reminders', 'guard_name' => 'admin'],
            ['name' => 'view basket statistics', 'guard_name' => 'admin'],
            ['name' => 'view baskets', 'guard_name' => 'admin'],
            ['name' => 'view cancellation requests', 'guard_name' => 'admin'],
            ['name' => 'view client custom fields', 'guard_name' => 'admin'],
            ['name' => 'view clients to match the', 'guard_name' => 'admin'],
            ['name' => 'view coupons', 'guard_name' => 'admin'],
            ['name' => 'view currencies', 'guard_name' => 'admin'],
            ['name' => 'view escalation rules', 'guard_name' => 'admin'],
            ['name' => 'view expenses', 'guard_name' => 'admin'],
            ['name' => 'view invoice billings', 'guard_name' => 'admin'],
            ['name' => 'view languages', 'guard_name' => 'admin'],
            ['name' => 'view network tools', 'guard_name' => 'admin'],
            ['name' => 'view payment gateways', 'guard_name' => 'admin'],
            ['name' => 'view promotions', 'guard_name' => 'admin'],
            ['name' => 'view recurring expenses', 'guard_name' => 'admin'],
            ['name' => 'view registrars', 'guard_name' => 'admin'],
            ['name' => 'view sms reports', 'guard_name' => 'admin'],
            ['name' => 'view ticket departments', 'guard_name' => 'admin'],
            ['name' => 'view ticket statuses', 'guard_name' => 'admin'],
        ];

        foreach ($permissions as $permission) {
            Permission::firstOrCreate([
                'name' => $permission['name'],
                'guard_name' => $permission['guard_name'],
            ]);
        }

        // AdminSeeder::syncPermissions() is the primary super-admin grant path but
        // cannot be re-run standalone safely. Attach any permissions that
        // PermissionSeeder adds beyond the initial AdminSeeder run so that
        // `db:seed --class=PermissionSeeder` alone leaves super-admin complete.
        $superAdmin = Role::firstWhere(['name' => 'super-admin', 'guard_name' => 'admin']);

        // Defensive sync — grant super-admin EVERY admin-guard permission.
        // Replaces the earlier hand-curated list (which drifted out-of-sync as
        // new permissions were added — caused past 403s on /admin/transactions
        // and similar. Auto-picks up PRC-227/231/236 keys + any
        // future additions without seeder edits.
        if ($superAdmin) {
            $allAdminPerms = Permission::where('guard_name', 'admin')->get();
            $superAdmin->syncPermissions($allAdminPerms);
        }
    }
}
