<?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('rides', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug');
            $table->text('description')->default('');
            
            // Foreign key relationships
            $table->foreignId('park_id')->constrained('parks')->cascadeOnDelete();
            $table->foreignId('park_area_id')->nullable()->constrained('park_areas')->nullOnDelete();
            $table->foreignId('manufacturer_id')->nullable()->constrained('manufacturers')->nullOnDelete();
            $table->foreignId('designer_id')->nullable()->constrained('designers')->nullOnDelete();
            $table->foreignId('ride_model_id')->nullable()->constrained('ride_models')->nullOnDelete();
            
            // Main attributes
            $table->string('category', 2)->default('');
            $table->string('status', 20)->default('OPERATING');
            $table->string('post_closing_status', 20)->nullable();
            $table->date('opening_date')->nullable();
            $table->date('closing_date')->nullable();
            $table->date('status_since')->nullable();
            
            // Physical characteristics
            $table->unsignedInteger('min_height_in')->nullable();
            $table->unsignedInteger('max_height_in')->nullable();
            $table->unsignedInteger('capacity_per_hour')->nullable();
            $table->unsignedInteger('ride_duration_seconds')->nullable();
            
            // Ratings
            $table->decimal('average_rating', 3, 2)->nullable();
            
            $table->timestamps();
            $table->softDeletes();

            // Indexes
            $table->unique(['park_id', 'slug']);
            $table->index('category');
            $table->index('status');
            $table->index('manufacturer_id');
            $table->index('designer_id');
            $table->index('ride_model_id');
        });
    }

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