<?php

declare(strict_types=1);

namespace Maestro\Core\Modules\HourRegistration\Http\Controllers;

use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maestro\Core\Http\Controllers\Controller;
use Maestro\Core\Modules\HourRegistration\Services\HourReportSummaryService;

final class HourReportsController extends Controller
{
    public function summary(Request $request, HourReportSummaryService $svc): JsonResponse
    {
        $params = validator($request->query(), [
            'from' => ['nullable', 'date'],
            'to' => ['nullable', 'date'],
            'group' => ['nullable', 'string', 'in:week,month'],
            'user_id' => ['nullable', 'integer'],
        ])->validated();

        return response()->json($svc->summarize($request->user(), $params));
    }
}
