<?php

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

/**
 * Web sitesi veri boşlukları (plan: "Veri Envanteri" bölümü):
 * - Turlara madde madde öne çıkanlar (highlights)
 * - Program günlerine yemek ve konaklama bilgisi (Jolly'nin "Konaklama / Yemek" satırı)
 * - Günübirlik transfer noktalarına kalkış/ara durak ayrımı (point_type)
 */
return new class extends Migration
{
    public function up(): void
    {
        foreach (['cultural_tours', 'international_tours', 'day_tours'] as $tourTable) {
            if (Schema::hasTable($tourTable) && ! Schema::hasColumn($tourTable, 'highlights')) {
                Schema::table($tourTable, function (Blueprint $table) {
                    $table->json('highlights')->nullable()->after('description');
                });
            }
        }

        foreach (['cultural_tour_itineraries', 'international_tour_itineraries', 'day_tour_itineraries'] as $itineraryTable) {
            if (Schema::hasTable($itineraryTable) && ! Schema::hasColumn($itineraryTable, 'meals')) {
                Schema::table($itineraryTable, function (Blueprint $table) {
                    $table->json('meals')->nullable();          // ["breakfast","lunch","dinner"]
                    $table->string('accommodation')->nullable(); // o gecenin oteli/konaklaması
                });
            }
        }

        if (Schema::hasTable('day_tour_transfer_points') && ! Schema::hasColumn('day_tour_transfer_points', 'point_type')) {
            Schema::table('day_tour_transfer_points', function (Blueprint $table) {
                $table->string('point_type', 20)->default('departure'); // departure | transfer
            });
        }
    }

    public function down(): void
    {
        foreach (['cultural_tours', 'international_tours', 'day_tours'] as $tourTable) {
            if (Schema::hasTable($tourTable) && Schema::hasColumn($tourTable, 'highlights')) {
                Schema::table($tourTable, fn (Blueprint $table) => $table->dropColumn('highlights'));
            }
        }

        foreach (['cultural_tour_itineraries', 'international_tour_itineraries', 'day_tour_itineraries'] as $itineraryTable) {
            if (Schema::hasTable($itineraryTable) && Schema::hasColumn($itineraryTable, 'meals')) {
                Schema::table($itineraryTable, fn (Blueprint $table) => $table->dropColumn(['meals', 'accommodation']));
            }
        }

        if (Schema::hasTable('day_tour_transfer_points') && Schema::hasColumn('day_tour_transfer_points', 'point_type')) {
            Schema::table('day_tour_transfer_points', fn (Blueprint $table) => $table->dropColumn('point_type'));
        }
    }
};
