<?php

namespace App\Modules\Discipline\Controllers;

use App\Core\BaseApiController;
use App\Modules\Discipline\Models\DisciplineLevelModel;
use CodeIgniter\HTTP\ResponseInterface;

/**
 * API untuk config level disiplin (rentang poin -> tindakan sekolah).
 */
class DisciplineLevelController extends BaseApiController
{
    /**
     * GET /api/discipline/levels
     */
    public function index(): ResponseInterface
    {
        $model = new DisciplineLevelModel();
        $rows  = $model->where('is_active', 1)
            ->orderBy('min_score', 'ASC')
            ->findAll();

        $data = array_map(static function (array $r) {
            return [
                'id'           => (int) $r['id'],
                'min_score'    => (int) $r['min_score'],
                'max_score'    => $r['max_score'] !== null ? (int) $r['max_score'] : null,
                'title'        => $r['title'],
                'school_action'=> $r['school_action'],
                'executor'     => $r['executor'],
            ];
        }, $rows);

        return $this->successResponse($data, 'Discipline levels');
    }
}

