<?php

namespace App\Http\Controllers;

use App\Services\SearchService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class SearchController extends Controller
{
  public function __construct(private readonly SearchService $service) {}

  public function buscaPrestadores(Request $request): JsonResponse
  {
    try {
      $dados = $this->service->buscaPrestadores($request->query('name'), $request->query('date'));
      return $this->successResponse(payload: $dados);
    } catch (\Exception $e) {
      Log::error("Erro ao buscar prestadores: " . $e->getMessage());
      return $this->errorResponse(message: __("messages.error_fetching_data"), code: 500);
    }
  }
}
