<?php

namespace App\Http\Controllers\V3\WebServices;

use App\Http\Controllers\Controller;
use App\Http\Requests\V3\WebServices\RoadMaintenanceStation\IndexRequest;
use App\Http\Traits\ApiResponse;
use App\Models\RahdariPoint;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class RoadMaintenanceStationController extends Controller
{
    use ApiResponse;

    public function index(IndexRequest $request): JsonResponse
    {
        $province = $request->province;
        $status = $request->status;
        $type = $request->type;

        $data = RahdariPoint::query()
            ->when($status, fn ($query, $status) => $query->where('status', $status))
            ->when($type, fn ($query, $type) => $query->where('type', $type))
            ->when($province, fn($query, $province) => $query->where('province_id', $province))
            ->get([
                    'id', 'province_name', 'city_name', 'name', 'status', 'type_fa', 'phone',
                    'code', 'lat', 'lng',
                ]);

        return $this->successResponse($data);
    }
}
