<?php

namespace App\Http\Controllers;

use App\Models\Order;
use App\Services\CustomerPortalService;
use Illuminate\Http\Request;

class PublicTrackingController extends Controller
{
    public function index()
    {
        return view('tracking.index');
    }

    public function show(Request $request, CustomerPortalService $portalService)
    {
        $data = $request->validate(['invoice_no' => ['required', 'string', 'max:80']]);
        $order = Order::query()->where('invoice_no', $data['invoice_no'])->firstOrFail();

        return view('tracking.show', ['tracking' => $portalService->trackingData($order)]);
    }
}
