<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('product_option_sets', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_id')->constrained()->cascadeOnDelete();
            $table->foreignId('option_set_id')->constrained()->cascadeOnDelete();
            $table->timestamps();

            $table->unique(['product_id', 'option_set_id']);
        });

        Schema::create('product_inner_options', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_id')->constrained()->cascadeOnDelete();
            $table->foreignId('inner_option_set_id')->constrained()->cascadeOnDelete();
            $table->timestamps();

            $table->unique(['product_id', 'inner_option_set_id']);
        });

        Schema::create('branch_products', function (Blueprint $table) {
            $table->id();
            $table->foreignId('branch_id')->constrained()->cascadeOnDelete();
            $table->foreignId('product_id')->constrained()->cascadeOnDelete();
            $table->boolean('is_available')->default(true);
            $table->decimal('custom_price', 10, 2)->nullable();
            $table->timestamps();

            $table->unique(['branch_id', 'product_id']);
            $table->index('is_available');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('branch_products');
        Schema::dropIfExists('product_inner_options');
        Schema::dropIfExists('product_option_sets');
    }
};
