<?php

declare(strict_types=1);

namespace App\Http\Controllers\Api\V1;

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

/**
 * GET /api/v1/me — token sahibi kullanıcı bilgisi ve ability listesi.
 */
class MeApiController extends Controller
{
    public function show(Request $request): JsonResponse
    {
        $user = $request->user();
        $token = $user->currentAccessToken();

        return response()->json([
            'data' => [
                'id' => $user->id,
                'name' => $user->name,
                'email' => $user->email,
                'roles' => $user->getRoleNames()->all(),
                'token_abilities' => $token?->abilities ?? [],
                'token_name' => $token?->name,
                'token_expires_at' => $token?->expires_at?->toIso8601String(),
            ],
        ]);
    }
}
