<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('patient_vitals', function (Blueprint $table) {
            $table->id('vital_id'); // Creates the vital_id column as an auto-incrementing primary key
            $table->unsignedBigInteger('patient_id'); // Define patient_id as an unsigned big integer
            $table->double('body_temperature')->nullable(); // Define body_temperature as a double precision value, allowing null
            $table->integer('pulse_rate')->nullable(); // Define pulse_rate as an integer, allowing null
            $table->integer('respiration_rate')->nullable(); // Define respiration_rate as an integer, allowing null
            $table->integer('blood_pressure_systolic')->nullable(); // Define blood_pressure_systolic as an integer, allowing null
            $table->integer('blood_pressure_diastolic')->nullable(); // Define blood_pressure_diastolic as an integer, allowing null
            $table->double('blood_oxygen')->nullable(); // Define blood_oxygen as a double precision value, allowing null
            $table->double('weight')->nullable(); // Define weight as a double precision value, allowing null
            $table->double('blood_glucose_level')->nullable(); // Define blood_glucose_level as a double precision value, allowing null
            $table->timestamp('recorded_at')->default(DB::raw('CURRENT_TIMESTAMP')); // Define recorded_at with a default value of current timestamp
            
            // Set up the foreign key constraint
            $table->foreign('patient_id')->references('patient_id')->on('patient')->onUpdate('no action')->onDelete('no action');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('patient_vitals');
    }
};
