<?php

namespace App\Models;

use App\Enums\QueueStatus;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;

class QueueEntry extends Model
{
    protected $fillable = [
        'organization_id', 'appointment_id', 'patient_id', 'doctor_id', 'location_id',
        'queue_scope_key', 'queue_date', 'token_number', 'status', 'arrival_at',
        'sent_to_doctor_at', 'completed_at', 'no_show_at', 'created_by_user_id',
    ];

    protected function casts(): array
    {
        return [
            'queue_date' => 'date',
            'token_number' => 'integer',
            'status' => QueueStatus::class,
            'arrival_at' => 'datetime',
            'sent_to_doctor_at' => 'datetime',
            'completed_at' => 'datetime',
            'no_show_at' => 'datetime',
        ];
    }

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

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

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

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

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