<?php

declare(strict_types=1);

namespace sammo;

if (PHP_SAPI !== 'cli') {
    http_response_code(404);
    exit;
}

chdir(dirname(__DIR__));
require_once 'lib.php';
require_once 'func.php';

$input = stream_get_contents(STDIN);
$keys = Json::decode($input);
if (!is_array($keys)) {
    fwrite(STDERR, "Expected a JSON array of item keys.\n");
    exit(2);
}

$result = [];
foreach ($keys as $key) {
    if (!is_string($key)) {
        continue;
    }
    $item = buildItemClass($key);
    $result[$key] = [
        'rawName' => $item->getRawName(),
        'name' => $item->getName(),
        'info' => $item->getInfo(),
        'cost' => $item->getCost(),
        'buyable' => $item->isBuyable(),
        'consumable' => $item->isConsumable(),
        'reqSecu' => $item->getReqSecu(),
    ];
}

echo Json::encode($result);
