<?php

namespace Modules\Vrc\Http\Controllers;

use App\Http\Controllers\Controller;
use Modules\Vrc\Entities\VrcRepairOrder;
use Modules\Vrc\Services\Contracts\InvoiceServiceContract;

/**
 * Public, tokenized repair-status tracker (spec §6.13) — a customer follows
 * their repair through the §4.3 lifecycle from an emailed/SMS link, no login.
 */
class PortalTrackController extends Controller
{
    public function show($token, InvoiceServiceContract $invoices)
    {
        $ro = VrcRepairOrder::with(['vehicle.make', 'vehicle.model', 'statusHistory'])
            ->where('tracking_token', $token)->firstOrFail();

        // The customer-facing milestone ladder (subset of the full state graph).
        $ladder = ['checked_in', 'in_progress', 'quality_check', 'ready_for_pickup', 'invoiced', 'completed'];
        $invoice = $ro->erp_invoice_id ? $invoices->statusForOrder($ro) : null;

        return view('vrc::portal.track', compact('ro', 'ladder', 'invoice'));
    }
}
