<?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('quote_transport_rules', function (Blueprint $table) {
            $table->id();
            $table->foreignId('organization_id')->constrained('organizations')->cascadeOnDelete();
            $table->string('name', 120);
            $table->string('city', 120)->default('*');
            $table->string('zone_keywords', 255)->nullable();
            $table->enum('pricing_mode', ['fixed', 'km'])->default('fixed');
            $table->decimal('fixed_amount', 12, 2)->default(0);
            $table->decimal('base_km', 8, 2)->default(0);
            $table->decimal('per_km_amount', 12, 2)->default(0);
            $table->decimal('min_amount', 12, 2)->default(0);
            $table->boolean('is_active')->default(true);
            $table->unsignedSmallInteger('sort_order')->default(100);
            $table->timestamps();

            $table->index(['organization_id', 'city', 'is_active'], 'qtr_org_city_active_idx');
        });
    }

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

