<?php
declare(strict_types=1);

namespace App\Modules\Disciplines\Services;

use App\Modules\Disciplines\Models\SportDiscipline;

class DisciplineService
{
    /**
     * Get all active disciplines.
     */
    public static function getActive(): array
    {
        return SportDiscipline::allActive();
    }

    /**
     * Get active disciplines filtered by category.
     */
    public static function getByCategory(string $category): array
    {
        return SportDiscipline::getByCategory($category);
    }

    /**
     * Get all active disciplines grouped by category.
     */
    public static function getGroupedByCategory(): array
    {
        $disciplines = SportDiscipline::allActive();
        $grouped = [];

        foreach (SportDiscipline::getCategories() as $key => $label) {
            $grouped[$key] = [];
        }

        foreach ($disciplines as $d) {
            $cat = $d['category'] ?? 'individual';
            if (!isset($grouped[$cat])) {
                $grouped[$cat] = [];
            }
            $grouped[$cat][] = $d;
        }

        return $grouped;
    }
}
