<?php

namespace App\Http\Controllers\Customer;

use App\Http\Controllers\Controller;
use App\Models\Order;
use Illuminate\Support\Facades\Auth;

class OrderController extends Controller
{
    public function index()
    {
        $orders = Order::with('vehicle', 'auctionVehicle', 'statusHistory')
            ->where('user_id', Auth::id())
            ->orderBy('created_at', 'desc')
            ->paginate(10);

        return view('customer.orders', compact('orders'));
    }

    public function show(string $id)
    {
        $order = Order::with('vehicle', 'auctionVehicle', 'bid', 'statusHistory.updater', 'invoices.payments')
            ->where('user_id', Auth::id())
            ->where('id', $id)
            ->firstOrFail();

        $trackingSteps = Order::trackingSteps();

        return view('customer.order-show', compact('order', 'trackingSteps'));
    }
}
