<?php

namespace App\Http\Controllers\Player;

use App\FiveM\Contracts\FrameworkAdapter;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Inertia\Inertia;
use Inertia\Response;

class StatsController extends Controller
{
    public function show(Request $request, FrameworkAdapter $adapter, string $citizenId): Response
    {
        $character = CharacterController::ownedCharacterOrAbort($request, $adapter, $citizenId);
        $metadata = $character->metadata;

        return Inertia::render('Player/Characters/Stats', [
            'citizenId' => $citizenId,
            'characterName' => $character->name,
            // QBCore commonly tracks these under player metadata; servers
            // with different metadata keys can adjust this mapping without
            // touching the adapter contract itself.
            'stats' => [
                'played_hours' => (float) ($metadata['playedhours'] ?? 0),
                'deaths' => (int) ($metadata['deaths'] ?? 0),
                'hunger' => (int) ($metadata['hunger'] ?? 100),
                'thirst' => (int) ($metadata['thirst'] ?? 100),
                'stress' => (int) ($metadata['stress'] ?? 0),
                'is_dead' => (bool) ($metadata['isdead'] ?? false),
            ],
        ]);
    }
}
