<?php
declare(strict_types=1);

namespace App\Modules\SportsActivity\Controllers\Api;

use App\Core\Controller;
use App\Core\Request;
use App\Core\Response;
use App\Modules\SportsActivity\Services\MirrorStateService;

class MirrorApiController extends Controller
{
    public function state(Request $request, string $id): Response
    {
        $date = $request->get('date', date('Y-m-d'));
        $state = MirrorStateService::getFacilityState((int) $id, $date);

        if (isset($state['error'])) {
            return $this->json(['error' => $state['error']], 404);
        }

        return $this->json($state);
    }
}
