<?php

namespace Database\Seeders;

use App\Support\Simulation\SimulationExpectations;
use App\Support\Simulation\SimulationReportReconciliationExpectations;
use Illuminate\Database\Seeder;
use RuntimeException;

class DemoSimulationSeeder extends Seeder
{
    public function run(): void
    {
        if (app()->environment('production') && ! config('simulation.enabled')) {
            throw new RuntimeException(
                'Demo simulation seeding is blocked in production. '
                .'Use a dedicated demo instance and set SIMULATION_DATA_ENABLED=true before running DemoSimulationSeeder.'
            );
        }

        // Demo data must always represent the exact, fully validated simulation dataset.
        // Runtime config changes apply only to this PHP process; they do not modify .env.
        config([
            'simulation.enabled' => true,
            'simulation.phase' => 'full',
            'simulation.anchor_date' => SimulationExpectations::ANCHOR_DATE,
            'simulation.as_of_date' => SimulationReportReconciliationExpectations::AS_OF_DATE,
        ]);

        $this->call(SimulationSeeder::class);

        if ($this->command) {
            $this->command->newLine();
            $this->command->info('Full demo simulation data seeded successfully.');
            $this->command->line('Branches: SIM-DAR, SIM-MZA, SIM-ARU');
            $this->command->line('Demo password: '.config('simulation.user_password'));
            $this->command->line('Example login: sim.dar.manager');
            $this->command->line('Validation: php artisan simulation:validate');
        }
    }
}
