<?php
namespace App\Http\Controllers\Admin\Inventory;
use App\Http\Controllers\Controller;
use App\Models\Inventory\Inventory;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class InventoryController extends Controller
{
    public function index(Request $request): JsonResponse
    {
        $query = Inventory::query()->with(['warehouse','material']);
        $query->when($request->warehouse_id, fn($q, $v) => $q->where('warehouse_id', $v));
        $query->when($request->material_id, fn($q, $v) => $q->where('material_id', $v));
        return $this->paginate($query->paginate($request->input('per_page', 50)));
    }
}
