<?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('vendor_service_features', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('vendor_service_id'); // Related vendor service
            $table->string('name'); // Feature name
            $table->text('description')->nullable(); // Feature description
            $table->enum('type', ['text', 'number', 'boolean', 'choice'])->default('text'); // Feature type
            $table->json('options')->nullable(); // Available options for choice features
            $table->decimal('price_adjustment', 10, 2)->default(0); // Price adjustment
            $table->enum('price_adjustment_type', ['fixed', 'percentage'])->default('fixed'); // Adjustment type
            $table->boolean('is_required')->default(false); // Whether feature is required
            $table->integer('sort_order')->default(0); // Display order
            $table->timestamps();

            // Indexes
            $table->index(['vendor_service_id', 'type']);
            $table->index('sort_order');

            // Foreign key
            $table->foreign('vendor_service_id')->references('id')->on('vendor_services')->onDelete('cascade');
        });
    }

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