<?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('hotel_services', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('name');
            $table->string('category', 30)->default('other'); // spa|swimming_pool|jacuzzi|pedicure|theater|banquet|gym|other
            $table->text('description')->nullable();
            $table->decimal('price', 12, 2)->default(0);
            $table->smallInteger('duration_minutes')->default(60);
            $table->smallInteger('capacity')->default(1);
            $table->string('image')->nullable();
            $table->boolean('available')->default(true);
            $table->timestamps();
        });

        Schema::create('service_bookings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('code', 20);
            $table->unsignedBigInteger('hotel_service_id')->index();
            $table->unsignedBigInteger('customer_id')->nullable();
            $table->string('customer_name');
            $table->string('phone')->nullable();
            $table->unsignedBigInteger('booking_id')->nullable(); // in-house room booking ref
            $table->dateTime('scheduled_at');
            $table->smallInteger('guests')->default(1);
            $table->string('status', 20)->default('pending'); // pending|confirmed|completed|cancelled
            $table->decimal('amount', 12, 2)->default(0);
            $table->boolean('paid')->default(false);
            $table->text('notes')->nullable();
            $table->timestamps();
        });

        Schema::create('cabs', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('vehicle');
            $table->string('plate_number', 20);
            $table->string('driver_name');
            $table->string('driver_phone')->nullable();
            $table->tinyInteger('capacity')->default(4);
            $table->string('status', 20)->default('available'); // available|on_trip|maintenance
            $table->timestamps();
        });

        Schema::create('cab_bookings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('code', 20);
            $table->unsignedBigInteger('cab_id')->nullable();
            $table->string('customer_name');
            $table->string('phone')->nullable();
            $table->string('pickup');
            $table->string('destination');
            $table->dateTime('pickup_at');
            $table->decimal('fare', 12, 2)->default(0);
            $table->string('status', 20)->default('pending'); // pending|assigned|completed|cancelled
            $table->unsignedBigInteger('booking_id')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        foreach (['cab_bookings', 'cabs', 'service_bookings', 'hotel_services'] as $tableName) {
            Schema::dropIfExists($tableName);
        }
    }
};
