<?php

namespace App\Models;

use App\Models\Concerns\BelongsToOwner;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class VisitVital extends Model
{
    use BelongsToOwner;

    protected $table = 'care_visit_vitals';

    protected $fillable = [
        'owner_ref',
        'organization_id',
        'visit_id',
        'patient_id',
        'care_unit_id',
        'bp_systolic',
        'bp_diastolic',
        'pulse',
        'temperature',
        'spo2',
        'respiratory_rate',
        'recorded_by',
        'recorded_at',
        'notes',
    ];

    protected function casts(): array
    {
        return [
            'temperature' => 'decimal:1',
            'recorded_at' => 'datetime',
        ];
    }

    public function visit(): BelongsTo
    {
        return $this->belongsTo(Visit::class, 'visit_id');
    }

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

    public function careUnit(): BelongsTo
    {
        return $this->belongsTo(CareUnit::class, 'care_unit_id');
    }
}
