<?php
// ─── GET /api/stock/lookups.php ──────────────────────────────────────────
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();

// Fetch distinct existing pump codes from stock
$pumpCodeRows = $db->rows(
    "SELECT DISTINCT pump_code FROM stock
     WHERE pump_code IS NOT NULL AND pump_code != ''
     ORDER BY pump_code"
);

Response::ok([
    'types'      => $db->rows("SELECT * FROM stock_types ORDER BY name"),
    'suppliers'  => $db->rows("SELECT * FROM suppliers  ORDER BY name"),
    'pump_codes' => array_column($pumpCodeRows, 'pump_code'),
]);