<?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_services', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('user_id'); // Vendor who owns the service
            $table->string('name'); // Service name
            $table->string('slug')->unique(); // URL-friendly slug
            $table->text('description'); // Service description
            $table->decimal('base_price', 10, 2); // Base price
            $table->string('category')->nullable(); // Service category
            $table->string('delivery_time')->nullable(); // Delivery time estimate
            $table->text('requirements')->nullable(); // Service requirements
            $table->json('features'); // Service features (JSON)
            $table->json('items')->nullable(); // Service items (JSON)
            $table->string('image_url')->nullable(); // Service image
            $table->enum('status', ['active', 'inactive', 'pending'])->default('pending');
            $table->boolean('is_featured')->default(false); // Featured service
            $table->integer('sort_order')->default(0); // Display order
            $table->timestamps();
            $table->softDeletes();

            // Indexes
            $table->index(['user_id', 'status']);
            $table->index('slug');
            $table->index('status');
            $table->index(['is_featured', 'sort_order']);

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

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