<?php
require __DIR__ . '/../bootstrap.php';

use Gestoreasy\Core\Fiscal\Sped\SpedFiscalGenerator;
use Gestoreasy\Core\Fiscal\Sped\Period;

// Usage: php scripts/generate_sped_cli.php [year] [month]
$year = isset($argv[1]) ? (int)$argv[1] : (int)date('Y');
$month = isset($argv[2]) ? (int)$argv[2] : (int)date('n');

try {
    $period = new Period($year, $month);
} catch (\Throwable $e) {
    fwrite(STDERR, "Invalid period: " . $e->getMessage() . "\n");
    exit(1);
}

$gen = new SpedFiscalGenerator();
$lines = $gen->generate($period, []);
foreach ($lines as $l) { echo $l, PHP_EOL; }
exit(0);