<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Models\LessonType;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;

final class LessonTypesController
{
    public function index(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface
    {
        $tenantId = $request->getAttribute('tenant_id');
        $types = LessonType::where('tenant_id', $tenantId)->orderBy('sort_order')->get();
        return $this->json($response, $types->toArray());
    }

    private function json(ResponseInterface $response, array $data, int $status = 200): ResponseInterface
    {
        $response->getBody()->write(json_encode($data));
        return $response->withStatus($status)->withHeader('Content-Type', 'application/json');
    }
}