<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('agent_logs', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('user_id');

            $table->string('type')->nullable();
            // z.B. event, note, task, system

            $table->text('input');

            $table->json('output')->nullable();
            $table->string('status');

            $table->integer('credits')->default(0);

            // 🔥 AI Token Tracking (wichtig für Kosten + Debugging)
            $table->integer('prompt_tokens')->default(0);
            $table->integer('completion_tokens')->default(0);
            $table->integer('total_tokens')->default(0);

            $table->string('model')->nullable();
            $table->decimal('cost_usd', 10, 6)->default(0);
            // 🔥 Performance
            $table->integer('duration_ms')->nullable();

            // 🔥 Raw AI Response (optional für Debugging)
            $table->json('ai_response')->nullable();

            $table->timestamps();

            $table->index('user_id');
        });
    }

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