<?php
// ─── GET /api/jobcards/next-no.php ───────────────────────────────────────
// Returns the next available jc_no by reading the max from work_requests.
define('ROOT', dirname(__DIR__, 2));
require_once ROOT . '/core/DB.php';
require_once ROOT . '/core/Response.php';
require_once ROOT . '/core/Auth.php';

Auth::require();
$db = DB::get();

$max = (int) $db->scalar("SELECT COALESCE(MAX(jc_no), 0) FROM work_requests");

Response::ok(['next_jc_no' => $max + 1]);