<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('parks', function (Blueprint $table) {
            // Area statistics
            $table->integer('total_areas')->default(0);
            $table->integer('operating_areas')->default(0);
            $table->integer('closed_areas')->default(0);
            
            // Ride statistics
            // Note: ride_count and coaster_count already exist in the parks table
            $table->integer('total_flat_rides')->default(0);
            $table->integer('total_water_rides')->default(0);
            
            // Visitor statistics
            $table->integer('total_daily_capacity')->default(0);
            $table->integer('average_wait_time')->nullable();
            // Note: average_rating already exists in the parks table
            
            // Historical data
            $table->integer('total_rides_operated')->default(0);
            $table->integer('total_rides_retired')->default(0);
            $table->date('last_expansion_date')->nullable();
            $table->date('last_major_update')->nullable();
            
            // Performance metrics
            $table->decimal('utilization_rate', 5, 2)->nullable();
            $table->integer('peak_daily_attendance')->nullable();
            $table->decimal('guest_satisfaction', 3, 2)->nullable();
            
            // Add indexes for common queries
            $table->index(['operator_id', 'ride_count']);
            $table->index(['operator_id', 'coaster_count']);
            $table->index(['operator_id', 'average_rating']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('parks', function (Blueprint $table) {
            $table->dropIndex(['operator_id', 'ride_count']);
            $table->dropIndex(['operator_id', 'coaster_count']);
            $table->dropIndex(['operator_id', 'average_rating']);
            
            $table->dropColumn([
                'total_areas',
                'operating_areas',
                'closed_areas',
                'total_flat_rides',
                'total_water_rides',
                'total_daily_capacity',
                'average_wait_time',
                'total_rides_operated',
                'total_rides_retired',
                'last_expansion_date',
                'last_major_update',
                'utilization_rate',
                'peak_daily_attendance',
                'guest_satisfaction',
            ]);
        });
    }
};
