<?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_price_items', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('price_list_id');
            
            $table->string('title')->nullable(); // E.g. Single FIT Net
            $table->decimal('net_price', 12, 2)->default(0);
            $table->decimal('sale_price', 12, 2)->default(0);
            $table->decimal('tax_rate', 5, 2)->default(20.00); // KDV rate e.g. 20%
            
            // JSON metadata column for polymorphic properties (e.g. room_type, board_type, market for hotels; route, flight_class for airlines, etc.)
            $table->json('metadata')->nullable();

            $table->timestamps();

            $table->foreign('price_list_id')->references('id')->on('supplier_price_lists')->onDelete('cascade');
        });
    }

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