// A distributor's GS1 data: what a scanner read from a carton's GS1-128 or DataMatrix, checked
// AI by AI; the element strings for new labels; the pallet's SSCC; GS1 Digital Link addresses
// for a QR code on the pack; and the content of the pallet's logistic label.
//
//   quillo run gs1_labels.qwe      then open http://localhost:8080/scan and http://localhost:8080/pallet

use "gs1_labels.qwer"

// A scanner's output: ]d2 (GS1 DataMatrix), then the data with GS after the variable-length lot.
route GET /scan = gs1_parse("]d20109501101530003101234AB\u{1d}17270131310200125021SN-0042")?

route GET /build = {
    label: gs1_build({ "01": "09501101530003", "10": "LOT-77", "15": "270430", "3103": "001250" })?,
    bad_check: gs1_build({ "01": "09501101530004" }).error,
    gtin14: gs1_gtin14("4006381333931")?,
    valid: [gs1_valid("4006381333931"), gs1_valid("4006381333932")],
}

route GET /link {
    let url = gs1_digital_link({ "01": "09501101530003", "10": "AB/12", "17": "270131", "21": "S42" }, "https://brand.example")?
    { url: url, back: gs1_digital_link_parse(url)?.elements | map((e) => `${e.ai}=${e.value}`) }
}

route GET /pallet {
    let sscc = gs1_sscc(3, "0950110", 4471)?
    gs1_logistic_label({
        from: ["Quillo Coffee Roasters", "12 Dock Road, Leeds LS1 4AB"],
        to: ["Café Montmartre", "75018 Paris"],
        sscc: sscc, content: "09501101530003", count: 48, batch: "L2610B", best_before: "2027-04-30", net_kg: 96.5,
        order: "PO-7731", ship_to_post: "75018",
    })?
}
