<?php

namespace App\Http\Controllers\V3\Dashboard;

use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\ObservedItem;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class ObservedItemController extends Controller
{
    use ApiResponse;
    public function show(ObservedItem $observedItem): JsonResponse
    {
        return $this->successResponse($observedItem);
    }

    public function filter(Request $request): JsonResponse
    {
        $columns = array(
            'id', 'item_id', 'road_patrol_id', 'roadPatrol.start_time', 'roadPatrol.end_time',
        );

        $allowedFilters = $columns;
        $allowedSortings = $columns;

        $data = ObservedItem::query()->whereNull('road_item_id');

        $dataTable = DataTableFacade::run(
            $data,
            $request,
            allowedFilters: $allowedFilters,
            allowedSortings: $allowedSortings
        );

        return response()->json($dataTable);
    }
}
