<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * Tarih×pazaryeri fiyat satırına sınıf boyutu (tour_class_id) ekler.
 * null = sınıf kullanılmıyor (tek fiyat). Unique anahtar sınıfı da kapsar.
 */
return new class extends Migration {
    public function up(): void
    {
        Schema::table('tour_date_marketplace_prices', function (Blueprint $t) {
            $t->unsignedBigInteger('tour_class_id')->nullable()->after('marketplace_id');
            $t->foreign('tour_class_id')->references('id')->on('tour_classes')->onDelete('cascade');
        });

        Schema::table('tour_date_marketplace_prices', function (Blueprint $t) {
            $t->dropUnique('tdmp_unique');
            $t->unique(['priceable_type', 'priceable_id', 'marketplace_id', 'tour_class_id'], 'tdmp_unique_cls');
        });
    }

    public function down(): void
    {
        Schema::table('tour_date_marketplace_prices', function (Blueprint $t) {
            $t->dropUnique('tdmp_unique_cls');
            $t->dropForeign(['tour_class_id']);
            $t->dropColumn('tour_class_id');
            $t->unique(['priceable_type', 'priceable_id', 'marketplace_id'], 'tdmp_unique');
        });
    }
};
