<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\StudentExamService;
use Illuminate\Http\JsonResponse;

class StudentPageController extends Controller
{
    public function __construct(
        private readonly StudentExamService $examService,
    ) {
    }

    public function index(): JsonResponse
    {
        return response()->json(
            $this->examService->buildPageListPayload()
        );
    }

    public function show(string $slug): JsonResponse
    {
        $result = $this->examService->buildPageDetailPayload($slug);

        $statusCode = match ($result['status'] ?? 'ok') {
            'missing' => 404,
            default => 200,
        };

        return response()->json($result, $statusCode);
    }
}
