<?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('recon_import_rows', function (Blueprint $table) {
            $table->id();
            $table->foreignId('batch_id')->constrained('recon_import_batches')->cascadeOnDelete();
            $table->unsignedInteger('row_number');
            $table->date('sale_date');
            $table->string('external_key');
            $table->string('external_label')->nullable();
            $table->unsignedInteger('qty');
            $table->unsignedBigInteger('amount');
            $table->string('order_status', 100)->nullable();
            $table->boolean('excluded')->default(false);
            $table->foreignId('product_id')->nullable()->constrained('products')->nullOnDelete();
            $table->timestamps();
            $table->index(['product_id', 'sale_date']);
            $table->index(['batch_id', 'external_key']);
        });
    }

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