<?php

namespace App\Database\Seeds;

use CodeIgniter\Database\Seeder;

/**
 * Loads demo/test data (roles, users, and sample rows across modules).
 *
 * Prefer the standalone script when CLI PHP is broken/outdated:
 *   php scripts/seed_demo_data.php
 *
 * Or with a healthy PHP 8.1+ CLI:
 *   php spark db:seed DemoDataSeeder
 *
 * Demo logins (password Demo@1234):
 *   boss         — full business access
 *   hrm          — HR manager
 *   attendance   — attendance only
 *
 * Idempotent: skips if user "boss" already exists.
 */
class DemoDataSeeder extends Seeder
{
    public function run(): void
    {
        $script = ROOTPATH . 'scripts' . DIRECTORY_SEPARATOR . 'seed_demo_data.php';

        if (! is_file($script)) {
            echo "Demo seed script not found at {$script}\n";
            return;
        }

        // Re-use the mysqli loader so CLI and web stay in sync.
        passthru(escapeshellarg(PHP_BINARY) . ' ' . escapeshellarg($script), $exitCode);

        if ($exitCode !== 0) {
            echo "Demo seed script exited with code {$exitCode}\n";
        }
    }
}
