<?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
    {
        Schema::create('witness_statements', function (Blueprint $table) {
            $table->id();
            $table->foreignId('solicitor_id')->constrained('solicitors')->cascadeOnDelete();
            $table->foreignId('client_id')->constrained('clients')->cascadeOnDelete();
            $table->foreignId('claim_id')->constrained('claims')->cascadeOnDelete();
            $table->string('status', 32)->default('draft');
            // Selected generation options, keyed by option key => bool.
            $table->json('generation_options')->nullable();
            // Points at the latest immutable version (no FK: versions reference this table).
            $table->unsignedBigInteger('current_version_id')->nullable();
            $table->timestamps();
            $table->softDeletes();

            // One workspace per claim.
            $table->unique(['claim_id']);
            $table->index(['solicitor_id', 'status']);
        });
    }

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