<?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('price_modifiers', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->enum('calculation', ['flat', 'percent']);
            $table->enum('operation', ['add', 'subtract'])->default('add');
            $table->decimal('value', 10, 2);

            $table->date('start_date')->nullable();
            $table->date('end_date')->nullable();
            $table->enum('type', ['all', 'weekday', 'weekend', 'custom', 'holiday']);
            $table->json('custom_days')->nullable();

            $table->integer('priority')->default(0);
            $table->timestamps();
        });

        Schema::create('modifier_category', function (Blueprint $table) {
            $table->foreignId('modifier_id')->constrained('price_modifiers')->cascadeOnDelete();
            $table->foreignId('category_id')->constrained('room_categories')->cascadeOnDelete();
            $table->primary(['modifier_id', 'category_id']);
        });

        Schema::create('modifier_room', function (Blueprint $table) {
            $table->foreignId('modifier_id')->constrained('price_modifiers')->cascadeOnDelete();
            $table->foreignId('room_id')->constrained('rooms')->cascadeOnDelete();
            $table->primary(['modifier_id', 'room_id']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('modifier_room');
        Schema::dropIfExists('modifier_category');
        Schema::dropIfExists('price_modifiers');
    }
};
