<?php

namespace App\Models;

use App\Core\Model;

/**
 * ITSWEBER CMS – EventCategory Model (Phase 4b)
 */
class EventCategory extends Model
{
    protected static string $table = 'iw_event_categories';

    /**
     * All categories with the number of associated events.
     */
    public static function allWithEventCount(): array
    {
        return static::db()->fetchAll(
            "SELECT c.*, COUNT(e.id) AS event_count
             FROM iw_event_categories c
             LEFT JOIN iw_events e ON e.category_id = c.id
             GROUP BY c.id
             ORDER BY c.name ASC"
        );
    }
}
