<?php
declare(strict_types=1);

function smm_now_iso(): string { return date('c'); }

function smm_json_response(array $arr, int $code=200): void {
  http_response_code($code);
  header('Content-Type: application/json; charset=utf-8');
  echo json_encode($arr, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE);
  exit;
}

function smm_read_json_body(): array {
  $raw = file_get_contents("php://input");
  if ($raw === false || trim($raw) === "") return [];
  $data = json_decode($raw, true);
  if (!is_array($data)) smm_json_response(["ok"=>false,"error"=>"Invalid JSON body"], 400);
  return $data;
}

function smm_str($v): string { return trim(strval($v ?? "")); }
