<?php

use App\Enums\PricelistFileLineStatusEnum;
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('pricelist_file_lines', function (Blueprint $table) {
            $table->id();
            $table->foreignId('pricelist_file_id')->constrained()->cascadeOnDelete();
            $table->integer('row_number');
            $table->enum('status', array_column(PricelistFileLineStatusEnum::cases(), 'value'))->index();
            $table->json('payload');
            $table->json('validation_messages')->nullable();
            $table->json('diff')->nullable();
            $table->timestamps();

            $table->index(['pricelist_file_id', 'status']);
        });
    }

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