<?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('file_chunks', function (Blueprint $table) {
            $table->id();
            $table->foreignId('upload_session_id')->constrained('upload_sessions')->cascadeOnDelete();
            $table->unsignedInteger('chunk_index');
            $table->string('chunk_path')->comment('Temporary S3 path for chunk');
            $table->unsignedInteger('chunk_size');
            $table->string('checksum', 64)->comment('Chunk checksum');
            $table->timestamp('uploaded_at')->nullable();

            $table->unique(['upload_session_id', 'chunk_index']);
            $table->index('upload_session_id');
        });
    }

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