<?php

namespace App\Http\Controllers\Api\System;

use App\Http\Controllers\Api\Core\BaseApiController;
use App\Http\Resources\System\DashboardRouteResource;
use App\Services\Dashboard\DashboardRouteService;
use Illuminate\Http\JsonResponse;
use Symfony\Component\HttpFoundation\Response;

class DashboardController extends BaseApiController
{
    public function __construct(private DashboardRouteService $service)
    {
        parent::__construct();
    }

    public function route(): JsonResponse
    {
        $user = auth()->user();
        if (!$user) {
            return $this->error('Unauthorized.', Response::HTTP_UNAUTHORIZED);
        }

        $payload = $this->service->resolveForUser($user);

        return $this->success([
            'dashboard' => new DashboardRouteResource($payload),
        ]);
    }
}
