<?php

namespace App\Http\Controllers\v1\Tenancy\Product;

use App\Http\Controllers\Controller;
use App\Http\Requests\Tenancy\Product\UpdateOrderStatusRequest;
use App\Models\Tenancy\Order;

class UpdateOrderStatusController extends Controller
{
    public function __invoke(string $orderId, UpdateOrderStatusRequest $request)
    {
        $order = Order::where('order_id', $orderId)->firstOrFail();
        $order->status = $request->status;
        $order->delivery_id = $request->delivery_id ?? null;
        $order->delivery_status = $request->delivery_status ?? null;
        $order->save();

        return $order;
    }
}
