<?php

namespace App\Http\Controllers\v1\Tenancy\Visit;

use App\Actions\Tenancy\Visit\GetAvailableHoursAction;
use App\Actions\Tenancy\Visit\GetBlockedDaysAction;
use App\Http\Controllers\Controller;
use Illuminate\Http\Response;
use Illuminate\Support\Carbon;
use Illuminate\Validation\ValidationException;

class GetAvailableHoursController extends Controller
{
    /**
     * @throws ValidationException
     */
    public function __invoke(int $specialistId,
                             int $procedureId,
                             Carbon $date,
                             GetBlockedDaysAction $getBlockedDaysAction,
                             GetAvailableHoursAction $availableHoursAction): Response
    {
        if ($getBlockedDaysAction->execute($specialistId, $procedureId, $date, $date)) {
            throw ValidationException::withMessages([
                'date' => 'The date is not available',
            ]);
        }

        return $this->ok($availableHoursAction->execute($specialistId, $procedureId, $date));
    }
}
