<?php

namespace App\Controllers;

use App\Models\PosOrderItemModel;
use App\Models\PosOrderModel;

/**
 * Simple live list of sent-to-kitchen orders, grouped by order, with a
 * per-item "mark ready" action. Kitchen staff don't move an order to
 * `served` themselves — that's a front-of-house call once they've
 * delivered it — they just clear items off their own queue.
 */
class KitchenDisplayController extends BaseController
{
    public function index()
    {
        $orders    = (new PosOrderModel())->kitchenQueue();
        $itemModel = new PosOrderItemModel();

        foreach ($orders as $order) {
            $order->items = $itemModel->forOrder($order->id);
        }

        return view('pos/kitchen', [
            'pageTitle' => 'Kitchen Display',
            'orders'    => $orders,
        ]);
    }

    public function markItemReady(int $itemId)
    {
        (new PosOrderItemModel())->markReady($itemId);

        return redirect()->to('pos/kitchen')->with('success', 'Item marked ready.');
    }
}
