<?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
    {
        if (Schema::hasTable('chat_logs') && !Schema::hasColumn('chat_logs', 'query_attempt')) {
            Schema::table('chat_logs', function (Blueprint $table) {
                // Which search attempt (1=exact, 2=relaxed, 3=fallback) found the result.
                // 0 = not a product search.
                $table->unsignedTinyInteger('query_attempt')->default(0)->after('confidence_score');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasTable('chat_logs') && Schema::hasColumn('chat_logs', 'query_attempt')) {
            Schema::table('chat_logs', function (Blueprint $table) {
                $table->dropColumn('query_attempt');
            });
        }
    }
};
