<?php
/** GET /api/cashflow/summary?period=30d — user cash flow */
require_once __DIR__ . '/../../config.php';
require_once __DIR__ . '/../../engine/Kernel.php';
Kernel::handle(['auth' => false, 'public' => true]);
require_once __DIR__ . '/../../engine/Logger.php';
require_once __DIR__ . '/../../engine/CashFlowEngine.php';

// session_start() removed — Kernel::handle manages sessions
$userId = (int)($_SESSION['user_id'] ?? 0);
if (!$userId){http_response_code(401);die(json_encode(['error'=>'not_authenticated']));}
$period = in_array($_GET['period']??'', ['7d','30d','90d']) ? $_GET['period'] : '30d';
echo json_encode(CashFlowEngine::analyze($userId, $period), JSON_UNESCAPED_UNICODE);
