<?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('request_versions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('request_id')->constrained('marketing_requests')->onDelete('cascade');
            $table->integer('version_number');
            $table->string('file_path');
            $table->string('original_filename');
            $table->string('mime_type')->nullable();
            $table->unsignedBigInteger('file_size')->default(0);
            $table->foreignId('uploaded_by')->constrained('users')->onDelete('cascade');
            $table->dateTime('uploaded_at');
            $table->dateTime('approved_at')->nullable();
            $table->foreignId('approved_by')->nullable()->constrained('users')->onDelete('set null');
            $table->timestamps();

            $table->unique(['request_id', 'version_number']);
        });
    }

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