const {
  extractOperators,
  extractNumbers,
  OPERATOR_POOL,
} = require('../src/lib/parameter_extractors');

function readArg(name, fallback) {
  const index = process.argv.indexOf(`--${name}`);
  if (index === -1 || index + 1 >= process.argv.length) return fallback;
  return process.argv[index + 1];
}

function readNumber(name, fallback) {
  const value = Number(readArg(name, fallback));
  return Number.isFinite(value) ? value : fallback;
}

function main() {
  const seed = readArg('seed', 'mazex-parameter-demo');
  const operatorCount = readNumber('operators', 5);
  const numberCount = readNumber('numbers', 5);
  const minScore = readNumber('min-score', 1);
  const maxScore = readNumber('max-score', 1000);
  const numberMin = readNumber('number-min', 1);
  const numberMax = readNumber('number-max', 1000);
  const allowNegative = process.argv.includes('--allow-negative');

  const operators = extractOperators({
    seed: `${seed}:operators`,
    count: operatorCount,
    minScore,
    maxScore,
  });
  const numbers = extractNumbers({
    seed: `${seed}:numbers`,
    count: numberCount,
    min: numberMin,
    max: numberMax,
    allowNegative,
  });

  console.log(
    JSON.stringify(
      {
        seed,
        operator_pool_size: OPERATOR_POOL.length,
        operators,
        numbers,
      },
      null,
      2,
    ),
  );
}

main();
