<?php

namespace Tests\Feature\Simulation;

use Database\Seeders\DemoSimulationSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;

class DemoSimulationSeederTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        Storage::fake('local');

        // Prove the demo wrapper itself selects the complete validated simulation.
        config([
            'simulation.enabled' => false,
            'simulation.phase' => 'foundation',
            'simulation.user_password' => 'Simulation@2026',
        ]);
    }

    public function test_demo_seeder_populates_the_complete_validated_dataset_and_can_be_rerun(): void
    {
        $this->seed(DemoSimulationSeeder::class);
        $this->seed(DemoSimulationSeeder::class);

        $this->assertTrue(config('simulation.enabled'));
        $this->assertSame('full', config('simulation.phase'));
        $this->assertSame('2026-08-01', config('simulation.anchor_date'));
        $this->assertSame('2026-08-15', config('simulation.as_of_date'));

        $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);
    }
}
