<?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('data_table_exports', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('resource_key', 64);
            $table->json('payload');
            $table->string('status', 32)->default('pending');
            $table->string('file_path', 512)->nullable();
            $table->timestamp('download_expires_at')->nullable();
            $table->text('error_message')->nullable();
            $table->timestamps();

            $table->index(['user_id', 'status']);
            $table->index('download_expires_at');
        });
    }

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