<?php

namespace App\Modules\Dashboard\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Dashboard\Services\PersonaAccessEvaluator;
use App\Modules\Dashboard\Services\PersonaLandingAssembler;
use Illuminate\Http\Request;
use Illuminate\View\View;

final class PersonaDashboardController extends Controller
{
    public function show(
        Request $request,
        PersonaAccessEvaluator $access,
        PersonaLandingAssembler $assembler,
        string $persona,
    ): View {
        $persona = strtolower($persona);
        abort_unless($access->isAllowedPersona($persona), 404);
        abort_unless($access->canAccess($request->user(), $persona), 403);

        return view('pages.dashboard.persona', [
            'persona' => $persona,
            'data' => $assembler->build($persona),
        ]);
    }
}
