<?php
declare(strict_types=1);

namespace App\Modules\SportsActivity\Models;

use App\Core\Model;
use App\Core\App;

class Program extends Model
{
    protected static string $table = 'sa_programs';
    protected static string $primaryKey = 'id';
    protected static bool $timestamps = true;
    protected static bool $softDelete = true;
    protected static bool $dispatchEvents = true;

    protected static array $fillable = [
        'code', 'name_ar', 'name_en', 'discipline_id', 'academy_id',
        'program_type', 'age_from', 'age_to', 'gender_restriction',
        'skill_level', 'description_ar', 'session_duration_minutes',
        'sessions_per_week', 'is_active',
    ];

    public static function getProgramTypeOptions(): array
    {
        return [
            'training' => 'تدريب',
            'recreational' => 'ترفيهي',
            'competitive' => 'تنافسي',
            'rehabilitation' => 'تأهيلي',
        ];
    }

    public static function getSkillLevelOptions(): array
    {
        return [
            'beginner' => 'مبتدئ',
            'intermediate' => 'متوسط',
            'advanced' => 'متقدم',
            'elite' => 'نخبة',
        ];
    }

    public static function getActive(): array
    {
        $db = App::getInstance()->db();
        return $db->select(
            "SELECT p.*, d.name_ar as discipline_name
             FROM sa_programs p
             LEFT JOIN sa_disciplines d ON d.id = p.discipline_id
             WHERE p.is_active = 1 AND p.is_archived = 0
             ORDER BY p.name_ar ASC",
            []
        );
    }
}
