<?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('conversations', function (Blueprint $table) {
			$table->id();
			$table->unsignedBigInteger('article_id')->nullable();
			$table->unsignedBigInteger('user_id');
			$table->string('type')->default('article_generation'); // article_generation, structure_planning, etc.
			$table->string('step')->default('step_1'); // step_1, step_2, step_3
			$table->json('context')->nullable(); // Store conversation context and history
			$table->json('messages')->nullable(); // Store all messages in conversation
			$table->json('ai_responses')->nullable(); // Store AI responses and generated content
			$table->string('status')->default('active'); // active, completed, cancelled
			$table->timestamps();
			
			$table->index(['article_id', 'user_id']);
			$table->index(['type', 'status']);
		});
	}
	
	/**
	 * Reverse the migrations.
	 */
	public function down(): void
	{
		Schema::dropIfExists('conversations');
	}
};
