<?php

declare(strict_types=1);

require_once __DIR__.'/warmup.php';

use Cin\AjaxSearch5\Licence;

$response          = new StdClass();
$response->status  = 'success';
$response->message = '';
$response->data    = new stdClass();
$headers           = getallheaders();
if (isset($headers['X-Reissue-Authorization'])) {
  $token = $headers['X-Reissue-Authorization'];
  $L     = new Licence();
  if ($L->reissueLicence($token)) {
    $response->message = 'licence successfully reissued';
  } else {
    $response->status  = 'error';
    $response->message = 'failed to reissue licence';
  }
} else {
  http_response_code(401);
  $response->status  = 'error';
  $response->message = 'auhtorization required';
}

header('Content-Type: application/json');
echo json_encode($response);
