<?php
// public/barcode.php
require_once __DIR__ . '/../helpers/barcode_utils.php';

header('Content-Type: application/json');

$input = $_GET['value'] ?? '';
$input = normalize_barcode_value($input);

if ($input === '') {
    echo json_encode(['ok' => false, 'message' => 'No barcode provided']);
    exit;
}

if (!is_supported_product_barcode($input)) {
    echo json_encode(['ok' => false, 'message' => 'Barcode must be numeric and at least 12 digits']);
    exit;
}

echo json_encode([
    'ok' => true,
    'type' => detect_barcode_type($input, false),
    'value' => $input,
]);
