<?php
// +-------------------------------------------------+
// 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
// +-------------------------------------------------+
// $Id: AutoritiesRouterRest.php,v 1.7.2.2 2026/06/19 13:42:54 qvarin Exp $

namespace Pmb\REST;

use Pmb\Common\Helper\Response;

if (stristr($_SERVER['REQUEST_URI'], basename(__FILE__))) {
    die("no access");
}

class AutoritiesRouterRest extends RouterRest
{
    /**
     * @var string
     */
    protected const CONTROLLER = "\\Pmb\\Autorities\\Controller\\ThesaurusUpdateController";


    protected function generateRoutes(): void
    {
        $this->post("/thesaurus/import/process", "processImport");
    }

    protected function call(\Pmb\REST\RouteRest $route)
    {
        global $data;

        $decoded = \encoding_normalize::json_decode(stripslashes($data ?? '{}'));
        if (empty($decoded) || !is_object($decoded)) {
            $decoded = new \stdClass();
        }

        $this->fetchRequirements();

        $className = static::CONTROLLER;
        $callback = [new $className($decoded), $route->getMethod()];
        if (is_callable($callback)) {
            return call_user_func_array($callback, $route->getArguments());
        }

        Response::notFound();
        return null;
    }
}
