<?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('rotulos_envio', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('envio_id')->index();
            $table->string('codigo_rotulo', 60)->unique();
            $table->enum('formato', ['10x15', 'media_carta', 'carta', 'termica'])->default('10x15');
            $table->text('qr_data')->nullable();        // base64 PNG del QR
            $table->text('barcode_data')->nullable();   // SVG del código de barras
            $table->json('contenido_snapshot')->nullable(); // snapshot del envio al momento de generar
            $table->boolean('impreso')->default(false);
            $table->timestamp('fecha_impresion')->nullable();
            $table->unsignedBigInteger('generado_por')->nullable();
            $table->timestamps();

            $table->foreign('envio_id')->references('id')->on('envios')->cascadeOnDelete();
        });
    }

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