<?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::create('parks', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->text('description')->nullable();
            $table->string('status', 20);
            
            // Details
            $table->date('opening_date')->nullable();
            $table->date('closing_date')->nullable();
            $table->string('operating_season')->nullable();
            $table->decimal('size_acres', 10, 2)->nullable();
            $table->string('website')->nullable();
            
            // Statistics
            $table->decimal('average_rating', 3, 2)->nullable();
            $table->integer('ride_count')->nullable();
            $table->integer('coaster_count')->nullable();
            
            // Foreign keys
            $table->foreignId('operator_id')
                ->nullable()
                ->constrained()
                ->nullOnDelete();
            
            $table->timestamps();
        });

        Schema::create('park_areas', function (Blueprint $table) {
            $table->id();
            $table->foreignId('park_id')
                ->constrained()
                ->cascadeOnDelete();
            $table->string('name');
            $table->string('slug');
            $table->text('description')->nullable();
            $table->date('opening_date')->nullable();
            $table->date('closing_date')->nullable();
            $table->timestamps();
            
            // Ensure unique slugs within each park
            $table->unique(['park_id', 'slug']);
        });

        // Create index for park status for efficient filtering
        Schema::table('parks', function (Blueprint $table) {
            $table->index('status');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('park_areas');
        Schema::dropIfExists('parks');
    }
};