<?php

namespace App\Repositories;

use App\Models\Niveau;

class NiveauRepository extends BaseRepository
{
    public function __construct(Niveau $model)
    {
        parent::__construct($model);
    }

    public function findByLibelle($libelle)
    {
        return $this->query->where('libelle', $libelle)->first();
    }

    public function findByCycle($cycleId)
    {
        return $this->query->where('cycle_id', $cycleId)->get();
    }

    public function getStatistics()
    {
        return [
            'total' => $this->count(),
            'by_cycle' => $this->query->select('cycle_id')
                ->selectRaw('count(*) as count')
                ->groupBy('cycle_id')
                ->get()
                ->pluck('count', 'cycle_id'),
        ];
    }
}
