<?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('markup_rules', function (Blueprint $t) {
            $t->id();
            $t->foreignId('company_id')->constrained()->cascadeOnDelete();
            $t->string('type');                          // category / brand / range
            $t->string('key')->nullable();               // pentru type=category|brand: numele
            $t->decimal('range_from', 10, 2)->default(0); // pentru type=range: limita inf
            $t->decimal('range_to', 10, 2)->nullable();   // pentru type=range: limita sup
            $t->decimal('markup_pct', 5, 2);             // ex 30 = +30%
            $t->unsignedSmallInteger('priority')->default(100);
            $t->boolean('is_active')->default(true);
            $t->timestamps();

            $t->index(['company_id', 'type', 'is_active', 'priority']);
        });
    }

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