<?php
declare(strict_types=1);

namespace App\Modules\PlayerAffairs\Models;

use App\Core\Model;

class AcademyEnrollment extends Model
{
    protected static string $table = 'academy_enrollments';
    protected static string $primaryKey = 'id';
    protected static bool $timestamps = true;
    protected static bool $softDelete = false;

    protected static array $fillable = [
        'player_id',
        'academy_id',
        'level_id',
        'schedule_id',
        'season',
        'enrolled_at',
        'enrollment_day',
        'status',
        'promoted_from_id',
        'dropped_at',
        'dropped_reason',
        'created_by',
    ];

    /**
     * Get enrollment statuses with Arabic labels.
     */
    public static function getStatuses(): array
    {
        return [
            'active'    => 'فعال',
            'suspended' => 'موقوف',
            'dropped'   => 'منسحب',
            'promoted'  => 'ترقية',
            'completed' => 'مكتمل',
        ];
    }

    /**
     * Get the Arabic label for a status.
     */
    public static function getStatusLabel(string $status): string
    {
        $statuses = self::getStatuses();
        return $statuses[$status] ?? $status;
    }

    /**
     * Get the badge color for a status.
     */
    public static function getStatusColor(string $status): string
    {
        $colors = [
            'active'    => '#059669',
            'suspended' => '#D97706',
            'dropped'   => '#DC2626',
            'promoted'  => '#7C3AED',
            'completed' => '#0284C7',
        ];
        return $colors[$status] ?? '#6B7280';
    }

    /**
     * Get all enrollments for a specific player.
     */
    public static function getForPlayer(int $playerId): array
    {
        return static::query()
            ->where('player_id', '=', $playerId)
            ->orderBy('created_at', 'DESC')
            ->get();
    }

    /**
     * Get all enrollments for a specific academy.
     */
    public static function getForAcademy(int $academyId): array
    {
        return static::query()
            ->where('academy_id', '=', $academyId)
            ->orderBy('created_at', 'DESC')
            ->get();
    }
}
