<?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::table('leads', function (Blueprint $table) {
            $table->unsignedTinyInteger('lead_score')->default(0)->after('rating');
            $table->string('temperature', 10)->default('cold')->after('lead_score');
            $table->timestamp('qualified_at')->nullable()->after('temperature');
            $table->index(['business_id', 'temperature'], 'leads_business_temperature_idx');
        });

        Schema::table('won_losts', function (Blueprint $table) {
            $table->string('payment_method')->nullable()->after('payment_status');
        });
    }

    public function down(): void
    {
        Schema::table('won_losts', function (Blueprint $table) {
            $table->dropColumn('payment_method');
        });

        Schema::table('leads', function (Blueprint $table) {
            $table->dropIndex('leads_business_temperature_idx');
            $table->dropColumn(['lead_score', 'temperature', 'qualified_at']);
        });
    }
};
