<?php
// ===== Patient Model =====
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Patient extends Model
{
    use SoftDeletes;

    protected $fillable = [
        'user_id', 'date_of_birth', 'gender', 'blood_type',
        'weight', 'height', 'national_id',
        'emergency_contact_name', 'emergency_contact_phone', 'emergency_contact_relation',
        'chronic_diseases', 'allergies', 'current_medications',
    ];

    protected $casts = [
        'date_of_birth' => 'date',
        'weight' => 'decimal:2',
        'height' => 'decimal:2',
    ];

    public function user() { return $this->belongsTo(User::class); }
    public function appointments() { return $this->hasMany(Appointment::class); }
    public function medicalRecords() { return $this->hasMany(MedicalRecord::class); }
    public function queues() { return $this->hasMany(Queue::class); }
    public function reviews() { return $this->hasMany(Review::class); }

    public function getAgeAttribute(): ?int
    {
        return $this->date_of_birth?->age;
    }
}
