<?php

declare(strict_types=1);

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

use Illuminate\Http\JsonResponse;
use Maestro\Core\Http\Controllers\Controller;
use Maestro\Core\Modules\HourRegistration\Http\Requests\HourInvoicingByClientRequest;
use Maestro\Core\Modules\HourRegistration\Services\HourInvoicingApiService;

final class HourInvoicingApiController extends Controller
{
    /**
     * Invoicing contract: documented under module {@see HourInvoicingApiService} and markdown.
     *
     * @return JsonResponse Stable JSON envelope for invoicing integrations.
     */
    public function byClient(HourInvoicingByClientRequest $request, HourInvoicingApiService $svc): JsonResponse
    {
        $payload = $svc->approvedBillableHoursForCustomer(
            $request->user(),
            (int) $request->validated('customer_id'),
            (string) $request->validated('from'),
            (string) $request->validated('to'),
        );

        return response()->json($payload);
    }
}
