<?php

namespace App\Models;

use App\Core\Model;

/**
 * ITSWEBER CMS – DownloadCategory Model (Phase 8)
 */
class DownloadCategory extends Model
{
    protected static string $table = 'iw_download_categories';

    /**
     * All categories with the number of associated downloads.
     */
    public static function allWithDownloadCount(): array
    {
        return static::db()->fetchAll(
            "SELECT c.*, COUNT(d.id) AS download_count
             FROM iw_download_categories c
             LEFT JOIN iw_downloads d ON d.category_id = c.id
             GROUP BY c.id
             ORDER BY c.sort_order ASC, c.name ASC"
        );
    }
}
