<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('care_vital_signs', function (Blueprint $table) {
            $table->string('source')->default('manual')->after('recorded_at'); // manual, device, import
            $table->foreignId('device_id')->nullable()->after('source')
                ->constrained('care_devices')->nullOnDelete();
            $table->json('raw_payload')->nullable()->after('device_id');
        });
    }

    public function down(): void
    {
        Schema::table('care_vital_signs', function (Blueprint $table) {
            $table->dropConstrainedForeignId('device_id');
            $table->dropColumn(['source', 'raw_payload']);
        });
    }
};
