<?php

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

/**
 * One row per completed (or skipped) care-routine slot. Pending slots are
 * computed from the care plan at render time, so only acted-on slots are stored.
 */
class CreateVaCareLogsTable extends Migration
{
    public function up()
    {
        if (Schema::hasTable('va_care_logs')) return;

        Schema::create('va_care_logs', function (Blueprint $table) {
            $table->increments('id');
            $table->unsignedInteger('admission_id');
            $table->unsignedInteger('care_plan_id')->nullable();
            $table->unsignedInteger('care_task_type_id');
            $table->date('care_date');
            $table->unsignedTinyInteger('slot_index')->default(0);
            $table->enum('status', ['done', 'skipped'])->default('done');
            $table->dateTime('done_at')->nullable();
            $table->unsignedInteger('done_by')->nullable();
            $table->string('notes', 500)->nullable();
            $table->timestamps();

            $table->index(['admission_id', 'care_date']);
            $table->index(['care_plan_id', 'care_date', 'slot_index']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('va_care_logs');
    }
}
