<?php

namespace App\Modules\Inventory\Controllers;

use App\Http\Controllers\Controller;
use App\Modules\Inventory\Models\Category;
use App\Modules\Inventory\Models\Warehouse;
use App\Modules\Inventory\Services\TurnoverService;
use Illuminate\Http\Request;
use Inertia\Inertia;

class InventoryAnalysisController extends Controller
{
    protected $turnoverService;

    public function __construct(TurnoverService $turnoverService)
    {
        $this->turnoverService = $turnoverService;
    }

    public function index(Request $request)
    {
        $filters = $request->only([
            'warehouse_id', 'category_id', 'search', 'per_page', 'sort_by', 'sort_order', 'status'
        ]);

        $analysisData = $this->turnoverService->getAnalysisData($filters, $request->input('per_page', 10));
        $kpis = $this->turnoverService->getKPIs($filters);

        return Inertia::render('Inventory/Analysis/Index', [
            'analysisData' => $analysisData,
            'kpis' => $kpis,
            'warehouses' => Warehouse::select('id', 'name')->get(),
            'categories' => Category::select('id', 'name')->get(),
            'filters' => $filters,
        ]);
    }
}
