<?php

declare(strict_types=1);

use App\Models\Deal;
use Database\Seeders\PricingTierSeeder;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Tests\Concerns\SharesSupplierPdo;

// Same in-transaction DB the command writes to and the assertions read.
uses(DatabaseTransactions::class, SharesSupplierPdo::class);

beforeEach(function (): void {
    (new PricingTierSeeder)->run();
    DB::statement("SELECT set_config('app.current_tenant_id', '0', true)");
});

/**
 * Task 14 — live `imitation:seed` command.
 *
 * The command self-contains the population scenario (funded clients on a shared
 * supplier source, region from tag with DaData disabled, snapshot rebuild, then
 * synthetic leads through the real RouteSupplierLeadJob) so a developer can review
 * the running portal "through the client's eyes". It must NEVER run on production.
 */
it('populates the running portal for UI review', function (): void {
    $this->artisan('imitation:seed', ['--leads' => 20, '--clients' => 3])
        ->assertExitCode(0);

    // The real routing + ledger pipeline ran → new deals exist for review.
    expect(Deal::where('status', 'new')->count())->toBeGreaterThan(0);
})->group('imitation');
