<?php

namespace App\Http\Controllers\ProvinceDashboard\PeopleMessages;

use App\Exports\PeopleMessages\SupervisorCartableExcel;
use App\Http\Controllers\Controller;
use app\Http\Traits\ApiResponse;
use App\Models\PeopleMessage;
use App\Services\Dashboard\Province\PeopleMessages\DataTableService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class SupervisorController extends Controller
{
    use ApiResponse;

    /**
     * Display a listing of the resource.
     */
    public function index(Request $request, DataTableService $dataTableService): JsonResponse
    {
        return response()->json($dataTableService->index($request));
    }

    public function excel(Request $request, DataTableService $dataTableService)
    {
        $name = 'گزارش از کارتابل پیام های سیستمی ' . now()->format('Y-m-d H:i') . '.xlsx';
        $data = $dataTableService->dataTable($request, true);
        return Excel::download(new SupervisorCartableExcel($data['data']), $name);
    }

    /**
     * Display the specified resource.
     */
    public function show(PeopleMessage $peopleMessage)
    {
        return $this->successResponse($peopleMessage);
    }
}
