<?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('promo_codes', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('code', 30);
            $table->string('type', 10)->default('percent'); // percent|fixed
            $table->decimal('value', 12, 2)->default(0);
            $table->string('applies_to', 15)->default('bookings'); // bookings|orders|both
            $table->integer('max_uses')->default(0); // 0 = unlimited
            $table->integer('used_count')->default(0);
            $table->date('starts_at')->nullable();
            $table->date('expires_at')->nullable();
            $table->string('status', 15)->default('active');
            $table->timestamps();
        });

        Schema::create('bed_types', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('name');
            $table->text('description')->nullable();
            $table->timestamps();
        });

        Schema::create('booking_types', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('name');
            $table->decimal('commission_percent', 5, 2)->default(0);
            $table->timestamps();
        });

        Schema::create('complementary_items', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('hotel_id')->nullable()->index();
            $table->string('name');
            $table->text('description')->nullable();
            $table->unsignedBigInteger('room_type_id')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        foreach (['complementary_items', 'booking_types', 'bed_types', 'promo_codes'] as $tableName) {
            Schema::dropIfExists($tableName);
        }
    }
};
