<?php

namespace Tests\Feature\Simulation;

use App\Support\Simulation\SimulationReportReconciliationExpectations;
use Database\Seeders\DatabaseSeeder;
use Database\Seeders\SimulationSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class SimulationFullSystemValidationTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        Storage::fake('local');
        config([
            'simulation.enabled' => true,
            'simulation.phase' => 'full',
            'simulation.anchor_date' => '2026-08-01',
            'simulation.as_of_date' => SimulationReportReconciliationExpectations::AS_OF_DATE,
            'simulation.user_password' => 'Simulation@2026',
        ]);
    }

    public function test_fresh_standard_seed_plus_full_simulation_passes_the_final_validation_gate_and_is_idempotent(): void
    {
        $this->seed(DatabaseSeeder::class);
        $this->seed(SimulationSeeder::class);
        $this->seed(SimulationSeeder::class);

        $exitCode = Artisan::call('simulation:validate', ['--json' => true]);
        $output = Artisan::output();

        $this->assertSame(0, $exitCode, $output);
        $this->assertStringContainsString('"status": "pass"', $output);
        $this->assertStringContainsString('"simulation_phase": "full"', $output);
        $this->assertStringNotContainsString('"status": "fail"', $output);
    }
}
