<?php

namespace App\Models;

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

class VitalSign extends Model
{
    use BelongsToOwner;

    protected $table = 'care_vital_signs';

    public const SOURCE_MANUAL = 'manual';

    public const SOURCE_DEVICE = 'device';

    public const SOURCE_IMPORT = 'import';

    protected $fillable = [
        'owner_ref', 'consultation_id', 'bp_systolic', 'bp_diastolic', 'pulse',
        'temperature', 'weight_kg', 'height_cm', 'spo2', 'respiratory_rate',
        'recorded_by', 'recorded_at', 'source', 'device_id', 'raw_payload',
    ];

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

    public function consultation(): BelongsTo
    {
        return $this->belongsTo(Consultation::class, 'consultation_id');
    }

    public function device(): BelongsTo
    {
        return $this->belongsTo(Device::class, 'device_id');
    }
}
