<?php
declare(strict_types=1);
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/conexao.php';
require_once __DIR__ . '/computadores_helpers.php';
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-store');
if (compEhCynthia()) { http_response_code(403); echo json_encode(['ok'=>false,'message'=>'Acesso negado.']); exit; }
$id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT) ?: 0;
if ($id <= 0) { http_response_code(422); echo json_encode(['ok'=>false,'message'=>'Equipamento inválido.']); exit; }
compGarantirEstrutura($mysqli);
$stmt = $mysqli->prepare("SELECT m.*, t.id AS termo_id, t.numero_termo, t.status AS termo_status FROM ti_computador_movimentacoes m LEFT JOIN ti_computador_termos t ON t.movimentacao_id = m.id WHERE m.computador_id = ? ORDER BY m.criado_em DESC, m.id DESC LIMIT 150");
$stmt->bind_param('i',$id);$stmt->execute();$res=$stmt->get_result();$itens=[];while($r=$res->fetch_assoc()){$itens[]=$r;}$stmt->close();
echo json_encode(['ok'=>true,'historico'=>$itens], JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);