<?php

class MenuCategory extends Model
{
    protected string $table = 'menu_categories';

    public function allOrdered(): array
    {
        return $this->db->query(
            "SELECT c.*, (SELECT COUNT(*) FROM menu_items mi WHERE mi.category_id = c.id) as item_count
             FROM menu_categories c ORDER BY c.display_order ASC, c.category_name ASC"
        )->fetchAll();
    }

    public function nextDisplayOrder(): int
    {
        $stmt = $this->db->query("SELECT COALESCE(MAX(display_order),0) as m FROM menu_categories");
        return (int) $stmt->fetch()['m'] + 1;
    }
}