<?php

declare(strict_types=1);

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('offer_rows', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('offer_section_id')->constrained()->cascadeOnDelete();
            $table->foreignId('offer_service_catalog_item_id')->nullable()->constrained('offer_service_catalog_items')->nullOnDelete();
            $table->longText('description_html')->nullable();
            $table->string('pricing_type', 24)->default('one_time');
            $table->string('custom_unit_label', 80)->nullable();
            $table->decimal('quantity', 15, 4)->default(1);
            $table->decimal('unit_price', 15, 4)->default(0);
            $table->string('discount_type', 24)->default('none');
            $table->decimal('discount_value', 15, 4)->default(0);
            $table->decimal('vat_rate', 8, 4)->default(0);
            $table->unsignedInteger('sort_order')->default(0);
            $table->timestamps();

            $table->index(['offer_section_id', 'sort_order']);
        });
    }

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