<?php

namespace Modules\Vrc\Http\Controllers;

use Illuminate\Http\Request;
use Modules\Vrc\Services\Forecast\DemandForecastService;

/**
 * Phase 5 — historical-trend analytics (§10.3): parts-demand forecast + upcoming
 * service-due load. Heuristic today; a natural delegation point to AiCore later.
 */
class ForecastController extends VrcBaseController
{
    public function index(Request $request, DemandForecastService $forecast)
    {
        $this->guard('vrc.reports.view');
        $bid = $this->businessId();

        $months = (int) $request->get('months', 6);
        $months = max(1, min(24, $months));

        $parts = $forecast->partsDemand($bid, $months);
        $serviceLoad = $forecast->upcomingServiceLoad($bid, 30);

        return view('vrc::reports.forecast', compact('parts', 'serviceLoad', 'months'));
    }
}
