<?php

namespace App\Http\Controllers\Account;

use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

/**
 * Read-only JSON usage endpoint at /account/storage-usage. Lives in the
 * /account/* group alongside ProfileController (auth + verified + tenant).
 *
 * Self-hosted users get `unlimited: true` (their `storageBytesLimit()`
 * returns null because the buyer owns their disk). The UI uses this to
 * suppress the cap-meter / upgrade-CTA and show a plain "X used" figure.
 */
class StorageUsageController extends Controller
{
    public function show(Request $request): JsonResponse
    {
        $user = $request->user();

        return response()->json([
            'used_bytes' => $user->storageBytesUsed(),
            'limit_bytes' => $user->storageBytesLimit(),
            'plan_key' => $user->activePlan()?->key,
            'unlimited' => $user->storageBytesLimit() === null,
        ]);
    }
}
