<?php

namespace App\Http\Controllers\ProvinceDashboard\SystemMessages;

use App\Exports\SystemMessage\OperatorCartableExcel;
use App\Http\Controllers\Controller;
use app\Http\Traits\ApiResponse;
use App\Models\SystemMessage;
use App\Services\Dashboard\Province\SystemMessages\OperatorService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;

class OperatorController extends Controller
{
    use ApiResponse;
    /**
     * Display a listing of the resource.
     */
    public function index(Request $request, OperatorService $operatorService): JsonResponse
    {
        return response()->json($operatorService->datatable($request));
    }

    /**
     * Display the specified resource.
     */
    public function show(SystemMessage $systemMessage): JsonResponse
    {
        return $this->successResponse($systemMessage->only(['id','duration','date', 'voice']));
    }

    public function download(string $id)
    {
        //
    }

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

    }
}
