<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Http\Resources\ProjectResource;

class ProjectController extends Controller
{
    /**
     * Display the specified project with its structure for the Content API.
     *
     * The endpoint is publicly accessible if the project has public_api enabled. Otherwise a
     * valid bearer token that belongs to the requested project is required.
     *
     * @param  Request  $request
     * @param  string   $uuid
     * @return \Illuminate\Http\JsonResponse|ProjectResource
     */
    public function show(Request $request)
    {
        // check if the token has the read ability
        if (!auth('sanctum')->user()->tokenCan('read')) {
            return response()->json(['message' => 'API token does\'nt have the right abilities!'], 403);
        }

        $project = $request->attributes->get('project');

        // The project has already been validated by middleware.

        return new ProjectResource($project);
    }
} 