<?php

namespace Modules\DermatologyClinic\Entities;

use Illuminate\Database\Eloquent\Model;
use Modules\ClinicCore\Entities\ClcPatient;

/**
 * A chronic-disease severity score (PASI / EASI / DLQI / IGA) recorded for a
 * shared ClinicCore patient at a point in time (1:many) — the data behind the
 * dermatology trend line.
 */
class DermaScore extends Model
{
    protected $table = 'derma_scores';
    protected $guarded = ['id'];

    protected $casts = [
        'value'       => 'float',
        'recorded_at' => 'datetime',
    ];

    /** score_type enum => [label, typical 0..max used only for the mini-chart scale]. */
    public const SCORE_TYPES = [
        'pasi' => ['PASI', 72],   // Psoriasis Area and Severity Index (0-72)
        'easi' => ['EASI', 72],   // Eczema Area and Severity Index (0-72)
        'dlqi' => ['DLQI', 30],   // Dermatology Life Quality Index (0-30)
        'iga'  => ['IGA', 4],     // Investigator's Global Assessment (0-4)
    ];

    public function patient()
    {
        return $this->belongsTo(ClcPatient::class, 'patient_id');
    }

    public function label(): string
    {
        return self::SCORE_TYPES[$this->score_type][0] ?? strtoupper((string) $this->score_type);
    }

    public function scaleMax(): float
    {
        return (float) (self::SCORE_TYPES[$this->score_type][1] ?? 100);
    }
}
