<?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('supplier_invoice_mappings', function (Blueprint $t) {
            $t->id();
            $t->foreignId('company_id')->constrained()->cascadeOnDelete();
            $t->foreignId('supplier_id')->constrained('suppliers')->cascadeOnDelete();
            $t->json('mapping_config');
                // {article_col:"B", name_col:"C", qty_col:"E", price_col:"F",
                //  brand_col:"D"|null, header_row:2, sheet_name:"Товары"|null}
            $t->string('sample_file_name', 200)->nullable();
            $t->timestamp('last_used_at')->nullable();
            $t->timestamps();
            $t->unique(['company_id', 'supplier_id'], 'sim_company_supplier_uniq');
        });
    }

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