<?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('daily_room_rates', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('room_id')->constrained()->cascadeOnDelete();
            $table->date('rate_date');
            $table->decimal('price_breakfast', 10, 2)->default(150);
            $table->decimal('price_no_breakfast', 10, 2)->default(120);
            $table->decimal('price_breakfast_3plus', 10, 2)->default(128);
            $table->decimal('price_no_breakfast_3plus', 10, 2)->default(102);
            $table->decimal('price_breakfast_discount', 10, 2)->default(135);
            $table->decimal('price_no_breakfast_discount', 10, 2)->default(108);
            $table->decimal('price_breakfast_discount_3plus', 10, 2)->default(116);
            $table->decimal('price_no_breakfast_discount_3plus', 10, 2)->default(92);
            $table->unsignedInteger('min_nights')->default(1);
            $table->boolean('is_closed')->default(false);
            $table->string('notes')->nullable();
            $table->timestamps();

            $table->unique(['room_id', 'rate_date']);
            $table->index(['rate_date', 'room_id']);
            $table->index(['room_id', 'is_closed']);
        });
    }

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