<?php

use App\Models\ConfigurationModel;

// app/Helpers/GlobalConfigHelper.php
if (!function_exists('getSemester')) {
    function getSemester() {
        $configModel = new \App\Models\ConfigurationModel();
        return $configModel->getConfig('semester');
    }
}

if (!function_exists('getSchoolYear')) {
    function getSchoolYear() {
        if (! is_cli() && session()->get('user_id')) {
            try {
                return service('schoolYearContext')->resolve(service('request'))->yearName();
            } catch (\Throwable $e) {
                log_message('warning', 'Falling back to configured school year: {message}', [
                    'message' => $e->getMessage(),
                ]);
            }
        }

        $configModel = new \App\Models\ConfigurationModel();
        return $configModel->getConfig('school_year');
    }
}
