<?php

namespace App\Http\Controllers;

use App\Services\DashboardService;
use App\Http\Resources\DashboardClienteResource;
use App\Http\Resources\DashboardPrestadorResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class DashboardController extends Controller
{
  public function __construct(private readonly DashboardService $service) {}

  public function dadosDashboardCliente(): JsonResponse
  {
    try {
      $dados = $this->service->dadosDashboardCliente();
      return $this->successResponse(
        payload: new DashboardClienteResource($dados),
      );
    } catch (\Exception $e) {
      Log::error("Erro ao obter dados do dashboard do cliente: " . $e->getMessage());
      return $this->errorResponse(message: __("messages.error_fetching_data"), code: 500);
    }
  }

  public function scheduleClienteDetails(int $id): JsonResponse
  {
    try {
      $dados = $this->service->getScheduleClienteDetails($id);
      return $this->successResponse(payload: $dados);
    } catch (\Exception $e) {
      Log::error("Erro ao obter detalhes do schedule do cliente: " . $e->getMessage());
      return $this->errorResponse(message: __("messages.error_fetching_data"), code: 500);
    }
  }

  public function dadosDashboardPrestador(): JsonResponse
  {
    try {
      $dados = $this->service->dadosDashboardPrestador();
      return $this->successResponse(
        payload: new DashboardPrestadorResource($dados),
      );
    } catch (\Exception $e) {
      Log::error("Erro ao obter dados do dashboard do prestador: " . $e->getMessage());
      return $this->errorResponse(message: __("messages.error_fetching_data"), code: 500);
    }
  }
}
