# Admin panel guide

## Getting in
Create the first super admin from the server (this is the **only** way to create one):

```bash
php artisan trevo:admin:create you@example.com "Your Name"     # prompts for a password (min 12 chars, letters + numbers)
```
Then open `/admin`. Anyone who is not an active admin gets a **404** there (the area is invisible to resellers).

## Roles and permissions (least privilege)
- `reseller`: normal customer. `admin`: can do **only** what is ticked for them. `super_admin`: everything, plus managing admins.
- Super admins create staff in **Admins & roles**: pick an existing registered account, tick permissions. Nobody can edit their own account or another super admin.

| Permission | Allows |
|---|---|
| `users.view` / `users.manage` | See resellers & history / suspend, activate, send reset link, disable all keys |
| `wallet.adjust` | Manual credit/debit (reason, confirmation, idempotent) |
| `deposits.review` | Approve/reject deposits flagged `manual_review` |
| `packages.manage` | Create/edit/activate packages |
| `catalog.manage` | Services, products, base prices, per-package prices |
| `orders.view` | Orders, items, wallet postings, scrubbed provider callbacks |
| `orders.resolve` | Provider lookup, retry (only never-sent orders), manual resolution |
| `orders.refund` | One-time refund of the charged amount |
| `vouchers.manage` | Decide on vouchers the provider rejected (void / return to stock) |
| `apikeys.manage` | Disable/enable/delete any API key |
| `logs.view` | API logs, webhook log, audit trail |
| `tickets.manage` / `announcements.manage` / `settings.manage` | Support, announcements, website settings + maintenance + provider status |

## Safety rules enforced in code
- Every sensitive action requires a written **reason** (min. 10 chars) and writes an **append-only audit row** (who, what, subject, reason, before/after, IP) in the same transaction as the change.
- All money moves go through the same ledger code as everything else (`WalletService`); there is no path that edits a balance directly.
- Refunds are **manual only** and one-time; automatic refunds do not exist because the refund policy is an owner decision.
- Manual order resolution requires per-item decisions and a confirmation tick; final orders can never be changed.
- Voucher codes are never displayed (only the last 4 characters). Provider secrets are never displayed or stored in the database.
- Admins cannot suspend themselves, other admins (unless super admin) or super admins.

## Maintenance mode
Website settings → tick **Maintenance mode**. Resellers see a 503 page and the API answers `503 maintenance`. Admins, sign-in and provider callbacks keep working.

## Day-to-day runbook
- **Order stuck in `manual_review`**: open it (Orders), press *Ask the provider now*; if still unresolved, verify at the provider, then *Resolve manually* per item.
- **Deposit in `manual_review`**: compare the gateway-reported amount shown with what the reseller requested, then approve (credits the *recorded* amount) or reject.
- **Reseller abuse / leaked key**: Resellers → *Disable all API keys* and/or *Suspend*.
- **Voucher in `review`**: check with the provider, then void it or return it to stock.
