<?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('dsars', function (Blueprint $table)
        {
            $table->id();
            $table->foreignId('solicitor_id')->nullable()
                ->constrained()
                ->cascadeOnDelete();
            $table->uuid('slug')->unique();
            $table->foreignId('tranche_id')->constrained('dsar_tranches');
            $table->foreignId('claim_id')->constrained();
            $table->foreignId('user_id')->constrained();
            $table->foreignId('institution_id')->constrained();
            $table->enum('status', ['draft', 'approved', 'needs posting', 'failed', 'sent', 'completed'])->default('draft');
            $table->longText('content');
            $table->string('file_path')->nullable();
            $table->timestamps();
            $table->timestamp('received_at')->nullable();
            $table->timestamp('posted_at')->nullable();
            $table->timestamp('expected_at')->nullable();
            $table->softDeletes();
        });
    }

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