<?php
require_once __DIR__ . '/../_pdo_db_connect.php';
require_once __DIR__ . '/../_response.php';
require_once __DIR__ . '/../middleware/auth_check.php';
$payload = require_auth();
$cid = (int)($_GET['customer_id'] ?? 0);
$page = max(1,(int)($_GET['page']??1)); $per = min(100,(int)($_GET['per']??20)); $off = ($page-1)*$per;
$pdo = get_db();
$sql = 'SELECT * FROM sd_followups WHERE 1=1'; $params = [];
if ($cid){ $sql .= ' AND customer_id=:cid'; $params[':cid']=$cid; }
$sql .= ' ORDER BY scheduled_at DESC LIMIT :off,:per';
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':off',$off,PDO::PARAM_INT); $stmt->bindValue(':per',$per,PDO::PARAM_INT);
foreach($params as $k=>$v) $stmt->bindValue($k,$v);
$stmt->execute();
json_res(['data'=>$stmt->fetchAll()]);
