<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('provider_services', function (Blueprint $table) {
            $table->id();
            $table->foreignId('vendor_type_id')->constrained('vendor_types')->onDelete('cascade');
            $table->string('name');                        // e.g. "Basic Plumbing"
            $table->text('description')->nullable();
            $table->string('icon')->nullable();
            $table->decimal('fixed_price', 10, 2);         // Admin-set fixed price
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        // Seed example services for Service Provider type (vendor_type_id = 1)
        DB::table('provider_services')->insert([
            ['vendor_type_id' => 1, 'name' => 'Plumbing',          'fixed_price' => 500.00, 'created_at' => now(), 'updated_at' => now()],
            ['vendor_type_id' => 1, 'name' => 'Electrical Work',   'fixed_price' => 600.00, 'created_at' => now(), 'updated_at' => now()],
            ['vendor_type_id' => 1, 'name' => 'AC Repair',         'fixed_price' => 800.00, 'created_at' => now(), 'updated_at' => now()],
            ['vendor_type_id' => 1, 'name' => 'Carpentry',         'fixed_price' => 700.00, 'created_at' => now(), 'updated_at' => now()],
            ['vendor_type_id' => 1, 'name' => 'Deep Cleaning',     'fixed_price' => 1200.00, 'created_at' => now(), 'updated_at' => now()],
        ]);
    }

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