<?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('orders', function (Blueprint $table) {
            $table->id();
            $table->string('student_name', 100);
            $table->foreignId('product_id')->constrained()->onDelete('cascade');
            $table->enum('size', ['small', 'medium', 'large'])->nullable();
            $table->json('text_characters'); // array of 8 characters
            $table->json('selected_stamps'); // stamp IDs and positions
            $table->string('preview_image_url', 255)->nullable();
            $table->enum('status', ['pending', 'completed'])->default('pending');
            $table->timestamps();
            
            $table->index(['status', 'created_at']);
        });
    }

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