<?php

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

/**
 * Rules that decide a lead's status automatically when a provider postback
 * credits it — e.g. auto-approve a specific offer/company, or hold a
 * suspicious user for manual review.
 */
return new class extends Migration
{
    public function up()
    {
        Schema::create('lead_rules', function (Blueprint $table) {
            $table->id();
            $table->string('match_field');      // company | offer_name | offer_id | user_id | country | trx
            $table->string('match_operator')->default('equals'); // equals | contains
            $table->string('match_value');
            $table->string('action')->default('approve'); // approve | hold | reject
            $table->boolean('is_active')->default(true);
            $table->unsignedInteger('sort_order')->default(0);
            $table->timestamps();

            $table->index(['is_active', 'sort_order']);
        });
    }

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