<?php
declare(strict_types=1);

namespace App\Modules\PlayerAffairs\Models;

use App\Core\Model;

class PlayerMedicalRecord extends Model
{
    protected static string $table = 'player_medical_records';
    protected static string $primaryKey = 'id';
    protected static bool $timestamps = true;
    protected static bool $softDelete = false;
    protected static bool $autoTrackAuthor = false;

    protected static array $fillable = [
        'player_id',
        'record_type',
        'certificate_type',
        'validity_months',
        'exam_date',
        'expiry_date',
        'doctor_name',
        'clinic_name',
        'issuing_authority',
        'cert_number',
        'result',
        'approval_status',
        'approved_by',
        'approved_at',
        'rejection_reason',
        'restrictions',
        'document_id',
        'notes',
        'created_by',
    ];

    /**
     * Get record types with Arabic labels.
     */
    public static function getRecordTypes(): array
    {
        return [
            'fitness_cert'   => 'شهادة لياقة',
            'medical_exam'   => 'فحص طبي',
            'blood_test'     => 'تحليل دم',
            'cardiac_screen' => 'فحص قلب',
            'other'          => 'أخرى',
        ];
    }

    /**
     * Get certificate types with Arabic labels.
     */
    public static function getCertificateTypes(): array
    {
        return [
            'recreational'  => 'ممارس',
            'academy'       => 'أكاديمي',
            'international' => 'دولي',
        ];
    }

    public static function getApprovalStatuses(): array
    {
        return [
            'pending'  => 'في الانتظار',
            'approved' => 'معتمد',
            'rejected' => 'مرفوض',
        ];
    }

    /**
     * Get medical results with Arabic labels.
     */
    public static function getResults(): array
    {
        return [
            'pending'     => 'في الانتظار',
            'fit'         => 'لائق',
            'conditional' => 'لائق بشروط',
            'unfit'       => 'غير لائق',
        ];
    }

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