<?php
declare(strict_types=1);

use App\Core\Database;

return function (Database $db): void {
    $permissions = [
        ['cashier.view_queue',      'عرض طابور الخزينة',    'View Cashier Queue'],
        ['cashier.process_payment', 'معالجة طلب دفع',       'Process Payment Request'],
        ['cashier.cancel_request',  'إلغاء طلب دفع',        'Cancel Payment Request'],
    ];

    foreach ($permissions as [$key, $ar, $en]) {
        $exists = $db->selectOne("SELECT 1 FROM role_permissions WHERE permission_key = ? LIMIT 1", [$key]);
        if ($exists) continue;

        $superAdmin = $db->selectOne("SELECT id FROM roles WHERE role_code = 'super_admin' AND is_active = 1 LIMIT 1");
        if ($superAdmin) {
            $db->insert('role_permissions', [
                'role_id'        => (int) $superAdmin['id'],
                'permission_key' => $key,
                'granted_at'     => date('Y-m-d H:i:s'),
            ]);
        }
    }

    echo "  Cashier permissions seeded.\n";
};
