<?php

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

/**
 * Adds `stage` to vai_queries so appointment-integrated AI checkpoints
 * (exam_review / diagnosis / treatment / interaction) are categorised
 * separately from the free-form assistant query types.
 */
class AddStageToVaiQueries extends Migration
{
    public function up()
    {
        if (Schema::hasTable('vai_queries') && !Schema::hasColumn('vai_queries', 'stage')) {
            Schema::table('vai_queries', function (Blueprint $table) {
                $table->string('stage', 30)->nullable()->after('query_type')->index();
            });
        }
    }

    public function down()
    {
        if (Schema::hasColumn('vai_queries', 'stage')) {
            Schema::table('vai_queries', function (Blueprint $table) {
                $table->dropColumn('stage');
            });
        }
    }
}
