<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class Patient extends Model
{
    use HasFactory;

    protected $fillable = [
        'organization_id', 'patient_code', 'user_id', 'name', 'phone', 'normalized_phone',
        'has_whatsapp', 'whatsapp', 'email', 'gender', 'date_of_birth', 'city',
        'blood_group', 'allergies', 'emergency_contact', 'notes', 'last_visit_at',
        'total_visits', 'created_by', 'updated_by', 'archived_at',
    ];

    protected function casts(): array
    {
        return [
            'has_whatsapp' => 'boolean',
            'date_of_birth' => 'date',
            'last_visit_at' => 'datetime',
            'archived_at' => 'datetime',
            'total_visits' => 'integer',
        ];
    }

    public function organization(): BelongsTo
    {
        return $this->belongsTo(Organization::class);
    }

    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    public function appointments(): HasMany
    {
        return $this->hasMany(Appointment::class);
    }

    public function queueEntries(): HasMany
    {
        return $this->hasMany(QueueEntry::class);
    }
}
