<?php

namespace App\Http\Controllers\V3\Dashboard\Reports;

use App\Exports\V2\RoadObservation\ReportComplaintsExport;
use App\Http\Controllers\Controller;
use App\Models\RoadObserved;
use App\Services\Cartables\RoadObservationTableService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Symfony\Component\HttpFoundation\BinaryFileResponse;

class RoadObservationReportController extends Controller
{
    public function index(Request $request, RoadObservationTableService $roadObservationTableService): JsonResponse
    {
        $data = $roadObservationTableService->reportIndex($request);
        return response()->json($data['data']);
    }

    public function excelReport(Request $request, RoadObservationTableService $roadObservationTableService): BinaryFileResponse
    {
        $name = 'گزارش رسیدگی به شکایات واکنش سریع ' . verta()->now()->format('Y-m-d H:i') . '.xlsx';
        $data = $roadObservationTableService->reportIndex($request);
        return Excel::download(new ReportComplaintsExport($data), $name);
    }
}
